Show Menu
Cheatography

Visual Basic Classic Cheat Sheet (DRAFT) by

Visual Basic before .NET

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Data types

Boolean
True / False
Byte
0 - 255
Integer
whole numbers
Long
big integers
Single
point numbers
Double
double accuracy
String
text
Variant
variable data type
visual basic 6 data types

variable declar­ation

Dim <va­r_n­ame> as <da­ta-­typ­e>
visual basic 6 variable declar­ation

Comments

'use the apostrophe
Visual basic 6 comment

Arithmetic operators

+
addition
-
subtra­ction
*
multip­lic­ation
/
division
\
integer division
^
power
Visual basic arithmetic operators

Error handling

On Error Resume Next
Skip error
Visual basic 6 Error handling

Sub Procedures

[ Public / Private ] Sub <na­me>
<Statements>
End Sub
Visual Basic 6 proced­ures.
Procedures are subpro­grams

Function Procedures

[Public / Private] Function <na­me> (<ar­g>) As <re­sul­t>
<Statements>
<na­me> = <re­sul­t>
End Function
Visual basic 6 function proced­ures.
Functions use a list of arguments (<a­rg>) to calculate a value (<r­esu­lt>)

Example Program

Private Sub btn_St­art­_Click (ByVal ...)
' Declar­ation of variables
Dim var1 As Single
Dim var2 As Single
'Enter the variable
var1 = txt_var1.Text
'Processing
var2 = var1
'Output of variable 2
lbl_var2.Text = var2
End Sub
Visual Basic 6 example program

Mathem­atical functions

Math.Round(<x­>,<­s>)
Round number
Math.Pow(<b­ase­>,<­exp­>)
Power number
Math.Sqr(<v­ar>)
Square root
<va­r1> Mod <va­r2>
Division remainder
x number
s number of digits precision
base is base number
exp is exponent number
var1 is dividend
var2 is divisor
Visual basic 6 Mathem­atical function

Declare arrays

Dim values ​​(0 to n) As <data type>
Dim values ​​() As <data type> = {w1, w2, w3, w4}
Visual basic 6 declare arrays

Go through array 1

For index = 0 To UBound­(array)
' input array
Array (index) = ...
Next
 

sequences

visual basic statement sequences

input

'Input via an object with text properties
<va­ria­ble> = <object name> .Text
Visual basic 6 input

output

'Output via an object with text property
<Object name> .Text = <va­ria­ble>
Visual basic 6 output

Selection

Visual basic 6 selection

Comparison operators

=
equal
<>
not equal
<
less than
>
bigger than
<=
less than or equal to
>=
greater than or equal to
Visual basic 6 comparison operators

if ... then

If <co­ndi­tio­n> Then
<Statements>
[ElseIf <co­ndi­tio­n> Then] ' optional condition
<Statements>
[Else]
<Statements>
End If

Select Case

Visual basic 6 select case

Select Case

Select Case <ex­pre­ssi­on>
Case 0 'simple value
<Statements>
Case 1 To 5 'multiple values
<Statements>
Case Is <5 'range of values
<Statements>
Case Else
<Statements>
End Select
Visual basic 6 Select Case

Iteration

Visual Basic 6 iteration

For Next

For <co­unt> = <st­art> To <en­d> Step <in­c>
<St­ate­men­ts>
Next
Visual basic 6 iteration 1

For Each

For Each <el­ement of all> In <all collec­tio­n>
<St­ate­men­ts>
Next
Visual Basic 6 iteration 2

Do Loop (head contro­lled)

Do While <co­ndi­tio­n>
<St­ate­men­ts>
Loop
or
Do Until <co­ndi­tio­n>
<St­ate­men­ts>
Loop
Visual basic 6 iteration 3