You are on page 1of 6

CODING

VISUAL BASIC
Variables
• A variable is a named storage location whose contents can be varied .
• It has a name and a data type.
• The name of the variable refers to the value stored in it.
• The data type tells what type of value can be stored in a variable.
RULES FOR VARIABLE
• It must be less than or equal to 255 characters.
• No spacing is allowed.
• It must not begin with a number.
• Periods are not permitted.
• It can not contain a hyphen (-).
• It must be unique within the same scope. A scope is the range
from which the variable can be referenced. E.g. A procedure, a
form and so on.
error
• Function 1 ()
•{
• DIM student AS string
•}
• Function2 ()
•{
• Text1.text = student;
•}
Declaring Variables
• Syntax
• DIM vname1 As Data Type, vname2 As Data Type
• DIM and As are keywords (a predefined word in VB).
• Vname1 and vanme2 are the name of variables.
• Example:
• Dim password As String
• Dim total As Integer
• Dim doDate As Date
• By default the type of the variable is variant. If we do not specify a data type, VB
assumes it to be variant. Example
• Dim flag

You might also like