Visual Basic 6 Reference Sheet
Variable Declaration
Dim <variable_name> As <data_type>
Ex. Dim sales As Integer
Data Types
Boolean, Byte, Currency, Date, Double, Integer, Long, Object, Single, String, Variant
Type Declaration
Dim <variable><suffix>
Suffixes
% - Integer, $ - String, @ - Currency, & - Long, # - Double, ! - Single
Comments
'Use the apostrophe like this
Arithmetic Operators
+(add), -(subtract), *(multiply), /(divide), \(integer divide), Mod(remainder), ^(power)
Logical Operators
AND, NOT, OR, XOR, IS, EQV, IMP, LIKE
Comparison Operators
=(equal to), <>(not equal to), <(less than), >(greater than), <=(lesser than or equal), >=(greater than or equal)
Bitwise Operator
AND, OR, NOT, XOR
IF/Else
If (<condition>) Then
<statements>
Else
<statements>
End If
Inline IF
variable = IIF(condition>,<value if true>,<value if false>
Case Statement
Select Case (<expression>)
Case(<expression 1>)[:]
<statements>
Case(<expression 2>)[:]
<statements>
Case(<expression n>)[:]
<statements>
<statements>
Case Else[:]
<statements>
<statements>
End Select
For Loop
For <counter> = <startval> To <endval> [Step [increment/decrement>]
<statements>
Next [<counter>]
Do While Loop
Do While(<expression>)
<statements>
Loop
Do-Loop-While
Do
<statements>
Loop While(<expression>)
Do-Until Loop
Do Until(<expression>)
<statements>
Loop
Do-Loop Until
Do (<expression>)
<statements>
Loop Until
While <expression>
<statements>
Wend
For-Each Loop
For Each <element> In <Group/Object>
<statements>
Next [element>]
Arrays
Dim <varname>(<MaxIndexVal>) As <DataType>
Dim <varname>(<MinIndexVal>) To (<MaxIndexVal>) As <DataType>
ReDim <varname> (<MaxIndexVal>)
Procedures
[Private/Public] Sub <name>(<ArgumentList>)
<statements>
End Sub
Functions
[Private/Public] Function <name>(<ArgumentList>) As <Return_Type>
<statements>
<Name>=return_value
End Function
Sub/Function <name>([Optional] argument1 as Type, argument2 as type)
Calling Procedures/Functions
[Call]<Name>[(ArgumentList)]
File Handling
OPEN <filename> for <mode> as <#handler>
mode: INPUT, OUTPUT, APPEND
For reading fields from a file into variables
INPUT <#handler>, <variable list>
For reading the entire line in the file into single string
LINE INPUT <#handler>, <string_variable>
For Writing Data
WRITE #1, <variable/constant/expression> 'Data with qoutes
PRINT #1, <variable/constant/expression> 'Data with qoutes
CLOSE <#handler>
Simple Error Handling
On Error Goto <LineNumber>
On Error Goto <Label>
On Error Resume Next
Visual Basic 6 Reference Sheet
Reviewed by code-dev
on
3:59 PM
Rating:
No comments: