Skip to content

Instantly share code, notes, and snippets.

@naranjja
Created April 23, 2015 16:56
Show Gist options
  • Save naranjja/dace9d08ce8e4e062d9a to your computer and use it in GitHub Desktop.
Save naranjja/dace9d08ce8e4e062d9a to your computer and use it in GitHub Desktop.
Private Sub Object_Event()
'Declare numbers in memory (variables)
Dim IntegerNumber As Integer
Dim ShortRealNumber As Single
Dim LongRealNumber As Double
'Declare numbers or strings as constant
Const IntegerNumber = #
Const TextString = "text"
'Declare text in memory (variable)
Dim TextString As String
'Allow user to input in a box
InputVariable = InputBox("Prompt",,["Title"])
'The Val holder makes the InputBox's string value into a double
DoubleVariable = Val(InputBox("Prompt"))
'The Ucase holder makes the InputBox's string value to upper case
StringVariable = Ucase(InputBox("Prompt"))
'The Ucase holder makes the InputBox's string value to lower case
StringVariable = Lcase(InputBox("Prompt"))
'Output in a box
OutputVariable = MsgBox("Output" & Variable,[Box type],["Title"])
'Or
MsgBox "Output" [& Variable] [& Token]
'Token for line break
vbNewLine
'Create a nested conditional
If VariableA Condition Then
If VariableB Condition Then
VariableC = NewValueA
Else
VariableC = NewValueB
End If
Else: VariableD = NewValueC
End If
'While loop (checks condition at start)
While Variable Condition
Action
Variable = Variable + Change
'If the variable doesn't change inside the loop, it will go on forever
While end
'The While end is sometimes written as Wend
'Do loop (checks condition at ending)
Do
Action
Variable = Variable + Change
'If the variable doesn't change inside the loop, it will go on forever
Loop until Variable Condition
'Call a user form
UserForm.show
'Hide a user form
UserForm.hide
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment