• Visual Basic isn't case-sensitive, but it preserves the capitalization in the statement where the name is declared.


  • Default data type if not specify
  • Slower to process and large foot-print
  • Store elements of single type
  • Index start from 0. Declaration also assume start from 0. Can be change with "Option Base" at the top of a module.
  • Inefficient is don't know the exact size of the array
  • Contiguous
  • Declare: Dim myArray(4) As Currency 'declare 5 elements
  • Access: myArray(index)
  • Multi-dimension: Dim myArray(0 To 4, 0 To 9) As Integer 'declare 5x10 array. Max 60-dimensional
  • Note: Array of variant data
Dim myArray(5) As Variant or
Dim myArray As Variant
myArray = Array(...)
  • Like dynamic array, elements can be of different types
  • Declare: Dim myArray As Collection
  • Add: myArray.Add "Element1", "Element2"
  • Access: myArray.Item(1) or myArray(1) or myArray("Element2")
  • Remove: myArray.Remove 1 or myArray.Remove "Element2"
  • Remove all: Set myArray = New Collection or Set myArray = Nothing


  • Only for variant
  • Initial value of variant type
  • Check with IsEmpty()
  • For variant, fields, and controls
  • Check with IsNull()
  • Cannot be compared to each other

Conditional LogicEdit

If StatementEdit

If <condition> Then
ElseIf <condition> Then
End If

For LoopEdit

Use "Exit For" to exit the loop

  • For counter=<start> To <end> [Step <step>]
    Next [counter]
  • For Each <object> In <collection|array>
    Next [counter]

Do LoopEdit

Use "Exit Do" to exit the loop

  • Do While <condition>
  • Do
    Loop While <condition>
  • Do Until <condition>
  • Do
    Loop Until <condition>

Select Case StatementEdit

Select Case <expression>

Case [value]
Case [multi values: 2, 5, 7]
Case [range: 2 To 7]
Case [comparison: val > 10]
Case Else

End Select


  • Use = to assign to a variable or constant
  • Use of Let is optional
  • Use Set to assign object


  • Start with apostrophe(') or Rem

Line ContinuationEdit

  • Use underscore(_)

String ConcatenationEdit

  • Use ampersand(&)

Function and SubroutineEdit


  • Return value
  • Set variable name the same as function name to return the value
  • To ignore the return value, call the function the way we call Sub--without parenthesis and pass parameters as usual


  • Does not return any value
  • Call: mySub arg1, arg2 or Call mySub(arg1,arg2)

Named ArgumentsEdit

Say we have Sub mySub(arg1 As Integer, arg2 As String)
We can call: mySub(5, "Friday") --parameter positions are important or
Use named parameters: mySub(arg2:="Friday", arg1:=5) --parameter positions are not important

Optional ArgumentsEdit

Sub mySub(arg1 As Integer, Optional arg2 As String) 'without default value
Sub mySub(arg1 As Integer, Optional arg2="Holiday" As String) 'with default value