Beginners Introduction to the Syntax and Symantics of the Visual Basic Programming Language
Variables are pre-declared in Visual Basic using As variable_type.
In Visual Basic, conditional operators like
If condition
... do something ...
Else
... do some-other-thing ...
End If
give different options for different conditions.
For instance:
If age > 18
MsgBox("You are grown-up now.")
Else
MsgBox("You are still young.")
End If
In Visual Basic, iteration operations are done using loops:
while loop:
Do While condition
... do something ...
End Do
and
for loop:
For i = 0 To a_number Then
... do something ...
Next
In Visual Basic, the arithmetic operators do exactly what you would expect:
+ means add;
- means subtract;
* means multiply;
/ means divide; and
% means moduli.
Note: Moduli means remainder after division.
Dividing 5 by 2 (5 ÷ 2) gives a remainder of 1.
Hence 5 % 2 = 1;
' is used for comments in Visual Basic.
Comments are just remarks (explanations) you write along side your
code for clarity purposes (help you define what you are doing);
and also for future remembrance of what a piece of code was meant for.
The compiler neither needs nor processes them.
Tip: You don't need to write out comments as you follow our demonstrations.
Visual Basic References
For a more thorough explanation of Visual Basic, please visit the following link:
Visual Basic Documentation - contains a lot of pictures and explanations; Ideal for total beginners.