This Visual Basic Cheatsheet is For You!
  1. Sample Program
  2. Public Module Program
     Public Sub Main(args() As string)
    Console.WriteLine("Hello, World!")
    End Sub
     End Module
    
  3. Example
    Dim byteVar As Byte
    Dim intVar As Integer = 100
    Dim doubleVar As Double
    Dim dateVar As Date 
    Dim charVar As Char = "A"
    Dim strVar As String = "OneCompiler"
    Dim boolVar As Boolean = TRUEt 
    
  4. Constants
  5. [ < attributeList > ] [ accessModifier ] [ Shadows ] Const constantName [ As datatype ] = value
    
  6. Operators
  7. Operator type	      Description
    Arithmetic Operator	+ , - , * , / , , MOD, ^
    Relational Operator	< , > , <= , >= , =
    BitWise Operator	AND, OR, XOR, NOT, AndAlso, OrElse, isTrue, isFalse
    BitWise Shift Operator	AND, OR, XOR, NOT, << , >>
    Logical Operator	&& , ||, !
    Assignment Operator	= , += , -= , *= , /=, = , %= ,<<=,>>=, &=, ^=
    Miscellaneous Operator	AddressOf, Await, GetType
              
  8. Strings
  9. Dim variableName As String
    Dim Name As String = "harismalik"
              
    
  10. Conditional Statements
  11. If condition-expression Then 
                'code
            End If
    
    If(conditional-expression)Then
       'code if the conditional-expression is true 
    Else
      'code if the conditional-expression is false 
    End If
    
    
    If(conditional-expression)Then
       'code if the above conditional-expression is true 
    Else If(conditional-expression) Then
            'code if the above conditional-expression is true 
        Else
            'code if the above conditional-expression is false 
    End If
    
    
    
    If(conditional-expression)Then
       'code if the above conditional-expression is true
       If(conditional-expression)Then
             'code if the above conditional-expression is true 
       End If
    End If
        
    
  12. Select Cases
  13. Select [ Case ] expression
    [ Case expressionlist
        'code ]
    [ Case Else
        'code ]
     End Select
    
  14. Loops
  15. For..Next
  16. For counter [ As datatype ] = begin To end [ Step step ]
    'code
    [ Continue For ]
    'code
    [ Exit For ]
    'code
     Next [ counter ]
    
  17. For..Each
  18. It is used to concatenate two strings

    For Each element [ As datatype ] In group
    'code
    [ Continue For ]
    'code
    [ Exit For ]
    'code
    Next [ element ]
    
  19. While
  20. While conditional-expression
    'Code 
    [ Continue While ]
    'Code
    [ Exit While ]
    'Code
    End While
    
  21. DO -while
  22. Do { While | Until } conditional-expression
    'Code
    [ Continue Do ]
     'Code
    [ Exit Do ]
    'Code
    Loop
    
  23. Functions
  24. Functions consists of a set of statements which perform a sepcific functionality and they return a value when they are called.

    [accessModifiers] Function functionName [(parameterList)] As returnType
    'code
    End Functioncode>
    
    
  25. Sub-Procedures
  26. Sub-procedures are similar to functions but they don't return any value.

    Sub ProcedureName (parameterList)
    'Code
    End Sub