Visual Basic Pointers
Visual Basic Pointers
1. an event procedure
An Event Procedure is a set of instructions to be executed when a certain event happens.
For example, we can write an Event Procedure for when we push an “OK” button.
Almost everything in Visual Basic is either an Event Procedure or used by an Event Procedure.
2. Tab index
Tab Order – Sets the order in which the controls are focused on when the user hits tab. To set the
tab order, number the TabIndex property of the controls starting at 0
3. parameters
Parameters are the local variables used in the function definition
Parameters can be used ONLY in the function they belong to
The difference between arguments and parameters is…
Arguments are the values you pass to a function
Parameters are the local variables used in the function header
4. Name
The naming (value of the name property) of controls should indicate what it is and what it does
5. Pseudocode
Pseudocode – English-like phrases with some Visual Basic terms to outline the task
Pseudocode is good for listing the steps of an algorithm in a form that is easier to translate into VB
There is NO SPECIFIC FORM to pseudocode, it can look as much like VB or English as you want.
6. Algorithm
An Algorithm is a step-by-step procedure devised for the purpose of taking in data and producing the
correct output.
A program is the actual implementation of an algorithm in a programming language.
Before writing a program, you must develop an algorithm to solve a problem
7. Keywords
Remember the ByVal keyword in front of the parameters?
This keyword indicates that all arguments are passed to this parameter by value
Keywords are words that have a particular meaning in VB. These are reserved, meaning they can’t
be used for other purposes (this will be clearer when we talk about variables)
8.underscore character
Variable names must start with an alphabetic character or an underscore (_)
After the first character they can have any alphabetic, numeric, or underscore character
Keywords cannot be used as variable names
Const makes the constant not able to take a different value after initialization
CONSTANT_NAME As Type = value
The name of the constant should be all in caps and have underscores instead of camel case for
different words
9.Variables
A variable declared in a function or event procedure can ONLY be used in the function or event
procedure where it was declared
A variable declared inside of a class, but not in any of its procedures can be used anywhere in the
class, including in any of its procedures
If a variable or constant is declared in a procedure, its lifetimeis from the time it is declared to the
end of the procedure.
Lifetime of a variable is the period where it still resides in memory
A variable or constant (or a parameter, really) declared in a procedure is called a local variable or
local constant (local to the procedure), and is said to have local scope.
A variable not declared in a procedure, but in a class definition is said to have class-level scope
A variable declared in an if statement, select case statement, or a loop (next chapters subject) is
said to have block-level scope. Also, its lifetime is untill the block (if, select case, etc.) ends
10.logical operators
Logical Operators – combine two or more relational expressions. Return either True or False
Logical Operators – And Or Not
11.nested If blocks
Any blocks can be nested in any other blocks (If statements can be nested in for loops, etc.)
You can put if statements in other if statements. This is called nesting.
12.InputBox
InputBox(prompt, title) prompt is the message displayed inside of the dialog box, title is the text
displayed in the title of the dialog box
13.Select Case
Select Case a
Case 1
‘do something
Case 2
‘do something
Case 3
‘do something
Case Else
‘do something
End Select
14.local scope
Local scope – can be referenced anywhere in the procedure in which it was declared in
A variable or constant (or a parameter, really) declared in a procedure is called a local variable or
local constant (local to the procedure), and is said to have local scope.
15.statement Const
Sometimes you want to define a variable that will keep the same value throughout the running of the
program. These are called constants.
Const CONSTANT_NAME As Type = value
Const makes the constant not able to take a different value after initialization
The name of the constant should be all in caps and have underscores instead of camel case for
different words
You need to initialize the constant for it to have a value
16.Function names
Typically, are camel case with first letter capitalized.
Follow the same naming rules as variables
Should be a verb that describe what the function does
FunctionName is the name of the function
17.Function procedure
Functions are used in programming to break complex problems into smaller ones
The code for the function is called the function definition
When calling a function, you must supply it with the same number of arguments as parameters
defined in the function definition.
You can create functions with no parameters. Just leave the parentheses empty when defining the
function.
A function MUST return a value
You can pass input to a function by supplying it with arguments.
18.user-defined function
Function FunctionName (ByVal var1 As Type, ByValvar2 As Type) As ReturnDataType
…
some code
…
Return expression
End Function
19.Do While loop
Do While loops repeat until the condition is… False
Do Until loops repeat until the condition is… True
20.Names of arguments
You can pass input to a function by supplying it with arguments.
Arguments are the values you pass to a function
Parameters are the local variables used in the function
21.Do Loop
Do Loops execute the code they contain until a condition is false.
Do Loops come in two forms: Pretest and Posttest.
For i As numberDataType = m To n
statement(s)
23.incremented or decremented
24.For…Next loop
When we know exactly how many times a loop should be executed, a special type of loop, a
For…Next loop, can be used.
For instance…
For i As Integer = 1 To 5
MessageBox.show(i)
Next
…will show the numbers 1 through 5 in message boxes.
By default, For…Next loops increment the counter variable by 1 every iteration of the loop.
You can also define how much is added to the counter variable every iteration. This amount is
called a step value.