In order to make you program easy to understand, and therefore easier to de-bug, it is a good idea to declare all your variables. Although VB does not force you it is a good habit to get into. Firstly it will save memory, by explicitly saying how big the variable will be, and also, if you ever use other languages like C++ you are not given the option of not declaring your variables. To declare a variable you use the following syntax:
Scope VariableName As DataType
Scope represents the range of the variable. VariableName is a string representing the name of the variable. DataType represents what sort of data is stored in the variable. If DataType is not specified, then it is set to Variant. For example,
Public NumberOfEmployees As Integer
if declared in the General Declarations section of a form, NumberOfEmployees can be accessed and changed in all procedures in that form. NumberOfEmployees can only store an Integer.
Comments