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 … [Read more...] about Control Flow Statements
Programming Fundamentals
vb If Then Statement
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 … [Read more...] about vb If Then Statement
If Then Else Statement
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 … [Read more...] about If Then Else Statement
Select Case Statement
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. . … [Read more...] about Select Case Statement
For Loop – For…Next Statement
Overview of For Loop in VB.NET The For loop in VB.NET is an essential construct that allows for a specified block of code to be executed a predetermined number of times. Whether you are iterating through arrays, performing batch operations, or … [Read more...] about For Loop – For…Next Statement
While Loop, Do While Loop, Do Until Loop, While End While
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 … [Read more...] about While Loop, Do While Loop, Do Until Loop, While End While
Nested Control Structures
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 … [Read more...] about Nested Control Structures
Subroutines
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 … [Read more...] about Subroutines
Functions
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 … [Read more...] about Functions
Arguments
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 … [Read more...] about Arguments
Argument-Passing Mechanisms
One of the most important topics in implementing your own procedures is the mechanism used to pass arguments. The examples so far have used the default mechanism: passing arguments by value. The other mechanism is passing them by reference. Although … [Read more...] about Argument-Passing Mechanisms
Built-in Functions
VB 2008 provides many functions that implement common or complicated tasks, and you can look them up in the documentation. (You'll find them in the Visual Studio ➢ Visual Basic ➢ Reference ➢ Functions branch of the contents tree in the Visual Studio … [Read more...] about Built-in Functions
Custom Functions
Most of the code we write is in the form of custom functions or subroutines that are called from several places in the application. Subroutines are just like functions, except that they don't return a value, so we'll focus on the implementation of … [Read more...] about Custom Functions
Passing an Unknown Number of Arguments
Generally, all the arguments that a procedure expects are listed in the procedure's definition, and the program that calls the procedure must supply values for all arguments. On occasion, however, you might not know how many arguments will be passed … [Read more...] about Passing an Unknown Number of Arguments
Named Arguments
You learned how to write procedures with optional arguments and how to pass a variable number of arguments to the procedure. The main limitation of the argument-passing mechanism, though, is the order of the arguments. By default, Visual Basic … [Read more...] about Named Arguments
Functions Returning Structures
Functions are not limited to returning simple data types such as integers or strings. They might return custom data types and even arrays. The capability of functions to return all types of data makes them very flexible and can simplify coding, so … [Read more...] about Functions Returning Structures
Functions Returning Arrays
In addition to returning custom data types, VB 2008 functions can also return arrays. This is an interesting possibility that allows you to write functions that return not only multiple values, but also an unknown number of values. In this … [Read more...] about Functions Returning Arrays
Overloading Functions
There are situations in which the same function must operate on different data types or a different number of arguments. In the past, you had to write different functions, with different names and different arguments, to accommodate similar … [Read more...] about Overloading Functions