The one thing you should have learned about programming in Visual Basic so far is that an application is made up of small, self-contained segments. The code you write isn’t a monolithic listing; it’s made up of small segments called procedures, and you work on one procedure at a time. The two types of procedures… [Continue Reading]
Programming Fundamentals
vb If Then Statement – Visual Basic 2008
The If. . .Then statement tests an expression, which is known as a condition. If the condition is True, the program executes the statement(s) that follow. The If. . .Then statement can have a single-line or a multiple-line syntax. To execute one statement conditionally, use the single-line syntax as follows: Conditions are logical expressions that… [Continue Reading]
vb If Then Else Statement – Visual Basic 2008
A variation of the If. . .Then statement is the If. . .Then. . .Else statement, which executes one block of statements if the condition is True and another block of statements if the condition is False. The syntax of the If. . .Then. . .Else statement is as follows: Visual Basic evaluates the condition;… [Continue Reading]
vb Select Case Statement – Visual Basic 2008
An alternative to the efficient but difficult-to-read code of the multiple ElseIf structure is the Select Case structure, which compares the same expression to different values. The advantage of the Select Case statement over multiple If. . .Then. . .ElseIf statements is that it makes the code easier to read and maintain. The Select Case… [Continue Reading]
VB For Loop – For…Next Statement in Visual Basic.NET 2008
Unlike the other two loops, the For. . .Next loop requires that you know the number of times that the statements in the loop will be executed. The For. . .Next loop has the following syntax: The keywords in the square brackets are optional. The arguments counter, start, end, and increment are all numeric. The… [Continue Reading]
VB While Loop – Do While Loop, Do Until Loop, While End While – VB2008
The Do. . .Loop executes a block of statements for as long as a condition is True, or until a condition becomes True. Visual Basic evaluates an expression (the loop’s condition), and if it’s True, the statements in the loop’s body are executed. The expression is evaluated either at the beginning of the loop (before… [Continue Reading]
Nested Control Structures in Visual Basic 2008
You can place, or nest, control structures inside other control structures (such as an If. . .Then block within a For. . .Next loop). Control structures in Visual Basic can be nested in as many levels as you want. The editor automatically indents the bodies of nested decision and loop structures to make the program… [Continue Reading]
Subroutines in Visual Basic 2008
The idea of breaking a large application into smaller, more manageable sections is not new to computing. Few tasks, programming or otherwise, can be managed as a whole. The event handlers are just one example of breaking a large application into smaller tasks. For example, when you write code for a control’s Click event, you… [Continue Reading]
Functions in Visual Basic 2008
A function is similar to a subroutine, but a function returns a result. Because they return values, functions — like variables — have types. The value you pass back to the calling program from a function is called the return value, and its type must match the type of the function. Functions accept arguments, just… [Continue Reading]
Arguments in Visual Basic 2008
Subroutines and functions aren’t entirely isolated from the rest of the application. Most procedures accept arguments from the calling program. Recall that an argument is a value you pass to the procedure and on which the procedure usually acts. This is how subroutines and functions communicate with the rest of the application. Subroutines and functions… [Continue Reading]