2. VARIABLES
• VARIABLE: is a factor that can
change in quality, quantity or size,
which you have to take into
account in situation
• For example you can
visualise a variable as a
box
In a memory that can
store specific value or
character
3. NAMING A VARIABLE
• Rule to adhere when
naming a variable
1. The name must be descriptive e.g.
school, mark.
2. It may not contain a space but more
than one word may be joined e.g.
nameofschool
3. It can contain letters and numbers,
but not numbers only e.g. class32
4. It must begin with a letter and not
start with a number
5. It can not contain any special
characters e.g. !@#$%^&
6. It may not be too long
7. The name cannot be a reserved word
in the language (e.g. integer, string)
• Naming using Hungarian
naming notation
Use the first three-letter
prefix on the first 3
characters of the variable
name
NB* the 3-letter prefix must
indicate the data type
4. Data types and prefix
Data type Prefix Example
Integer Int Inttotal
Decimal Dec decamount
String Str Strname
Boolean Bln Blnvalueentered
Double Dbl Dblpaid
Single Sng Sngtemp
Character Cha Chadept
Long Lng Lngproduct
Short shr shrnumstudent
5. DECLARATION
• A variable must be
declared in order to be
used
Declaration
(Dim strname as string)
Dim indicate the block level or procedure
level scope
Strname indicate a variable name
String indicate data type
• ERRORS
1. Syntax error
2. Warning error
messages
3. Logical error
4. Run-time error
6. Evaluation of errors
• Syntax error
• It is mostly a spelling error
• Leaving out a required characters
• On vb.net you code will be underlined by
a blue line to show a syntax error
Intnumber1= cint(txtnumber2.text)
• Warning error messages
This is more like rebuild error
7. Evaluation of errors
• Logical error
This can cause the application to give
wrong results
e.g. calculating average
Average = number1 + number 2 / 2
(wrong results)
Average = (number 1 + number 2)/2
(correct results)
• Run-time errors
Can be caused by the program not being able
to execute a statement given.
e.g. multiplying a string and a value
Textbox1.text= strname * 2
Vb.net will highlight you code in yellow where
an error occurred