To set the value of a variable you use the following syntax:
VariableName = Value
Where VariableName is the name of the Variable, and Value is the value to be stored. An error will occur if Value is not the correct datatype for that variable.
' General Declarations Section
Dim NumberofEmployees As Integer
' Form Load Procedure
Sub Form1_Load()
' Set the variable value
NumberofEmployees = 150
End Sub
This sets the value of NumberofEmployees to 150 when Form1 Loads
To get the value contained in a variable, you simply put the variablename in place of where you would otherwise type the value:
' General Declarations Section
Dim NumberofEmployees As Integer
' Form Load Procedure
Sub Form1_Load()
' Set the variable value
NumberofEmployees = 150
End Sub
' Command Button1 Procedure
Sub Command1_Click()
Msgbox "The number of employees is: " & NumberofEmployees
End Sub
The previous code displays a message 'The Number of employees is 150' when Command1 is clicked.
Comments