CSCA02 Visual Basic Summary

Predefined Functions

Str(n)         - converts numeric expression n to a string
Val(str)       - converts string expression str to a number
Chr(n)         - returns nth character of the current font
Asc(str)       - returns number corresponding to the 1st character of str. 
Len(str)       - returns number of characters in string str
LTrim(str)     - removes all spaces from beginning of string str 
RTrim(str)     - removes all spaces from end of string str
Trim(str)      - remove all spaces from both ends of string str
Left(str, n)   - leftmost n characters of string str
Right(str, n)  - rightmost n characters of string str
Mid(str, m, n) - return substring of str beginning with the mth
                 character of str and containing up to n characters.
InStr(n, str1, str2) - search for str2 within str1, starting at
                       the nth character in str1.  Return position where str2
                       is found in str1, or return 0 if not found.
IsNumeric(e)   - returns True if expression e is a numeric value; False otherwise
LCase(str)     - converts all alphabet characters in str to lower case
UCase(str)     - converts all alphabet characters in str to upper case
Format (e, f)  - format expression e using format type f, such as
                "Fixed", "Currency", "0.00", "0.0", etc.

Predefined Math Functions

Abs(n) - absolute value, |num|
Sqr(n)  - square root value of a non-negative number, num
Sin(n)  - trigonometric sine function
Cos(n)  - trigonometric cosine function
Tan(n)  - trigonometric tangent function

Statements

Private Sub <buttonname>_Click()  - start of a subprogram
Dim              - used to declare a variable
Const            - used to declare a constant
Do While Loop    - used for repetition
For To Step Next - used for repetition
If ElseIf Else   - used for selection
End If           - ends an if statement
End Sub          - ends a subprogram
End              - terminates the execution of a program
Option Explicit  - this statement is required in the General Declarations
                  section of every program you write, to force all variables to be
                  explicitly declared.  This will help you to avoid bugs.

User Interface

MsgBox str1, vbOkOnly, str2 - displays message str1 in a dialog box
                              with an OK button, and with a window title of str2
Call PrintForm        - used to print the form on the default printer
InputBox (str1, str2) - displays a dialog box, containing message str1 and
                        window title str2, that allows the user to enter a value.
                        The value by the user entered is returned.
<object>.setFocus     - sets the focus on a particular object on the form

Logical Operators

C1 And C2   - True if both C1 and C2 are true; False otherwise
C1 Or C2    - True if either or both of C1 and C2 are true; False otherwise
Not C1      - True if C1 is false; False otherwise

Data Types

Integer  - integer numbers using 16 bits
Single   - floating point numbers using 32 bits
String   - character values, e.g., "Hello"
Boolean  - holds a True or False value
Currency - currency values using 64 bits
Double   - floating point numbers using 64 bits [use Single instead]
Long     - integer numbers using 32 bits [use Integer instead]
Byte     - integer numbers from 0 to 255 using 8 bits [use Integer instead]
Date     - dates using 64 bits [not used in CSCA02]
Variant  - can be assigned any type of value [not used in CSCA02]

Predefined Constants

vbTab     - gives a tab character
vbNewLine - gives a carriage return and line feed character
vbOKOnly  - second parameter for MsgBox statement

Form Objects

TextBox       - box used for text entry
Label         - area where text can be displayed
CommandButton - user clicks on this and the corresponding code is executed
OptionButton  - used to select one option [not often used in CSCA02]
CheckBox      - used to select different options [not often used in CSCA02]