Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

SEB’s VB.

NET Guide

Visual Basic Syntax

Variables:
Declare variables using the following syntax:

Dim varname as vartype

It is good practice to use a 3 letter prefix to indicate the variable scope and type in the
name. The name should also be intrinsically meaningful, identifying the purpose of
the variable.

Scope:

l – local
m – modular
g – global

Type:

int – integer sin – single


bln - boolean dbl - double
str – string

Examples:

Dim lintCount as Integer (whole numbers)


Dim lstrName as String (Strings / text)
Dim lblnFinished as Boolean (True / false)
Dim ldblWage as Double (Real / floating point numbers – with decimal places)

All of these variables have been declared locally.

Variables can be declared at various levels – ie: to be used within different areas of
your project. Local variables (variables to be used only within a specific procedure or
function) and modular variables (variables that can be used throughout a class – the
code associated with a form) are both declared using the key word Dim. Variables can
be declared with modular scope by placing the declaration at the top of the page of
code; or locally by placing the declaration within the sub-routine. Global variables
can be declared using the key word Public. Global variables can be used throughout
the project but should be used rarely & with care as they are harder to track and can
cause confusion. It is good practice to put OPTION EXPLICIT at the top of the
page as it will enforce the declaration of variables.

Page 1 of 1

You might also like