VB.net Tutorials

1. Scope in VB.net

By: Steven Holzner : 2010-11-17

Description: The scope of an element in your code is all the code that can refer to it without qualifying its name (or making it available through an Imports statement). In other words, an element's scope is its accessibility in your code. As we write larger programs, scope will become more important, because we'll be dividing code into classes, modules, procedures, and so on. You can make the elements in those programming constructs private, which means they are tightly restricted in scope.


2. Unstructured Exception Handling in VB.net

By: Steven Holzner : 2010-11-17

Description: The old error-handling mechanism in VB6 and before is now called unstructured exception handling, and it revolves around the On Error Goto statement. You use this statement to tell VB .NET where to transfer control to in case there's been an exception, as in this case, where I'm telling Visual Basic to jump to the label "Handler" if there's been an exception. You create labels in your code with the label name followed by a colon, and the exception-handling code will follow that label


3. Structured Exception Handling in VB.net

By: Steven Holzner : 2010-11-17

Description: Visual Basic also supports structured exception handling. In particular, Visual Basic uses an enhanced version of the Try…Catch…Finally syntax already supported by other languages, such as Java. Here's an example that follows our previous example handling a division by zero exception; I start by creating a Try block—you put the exception-prone code in the Try section and the exception-handling code in the Catch section:


4. Creating Sub Procedures in VB.net

By: Steven Holzner : 2010-11-17

Description: We know all about Sub procedures: They're the handy blocks of code that can organize your code into single-purpose sections to make programming easier. Unlike functions, Sub procedures do not return values, but like functions, you can pass values to Sub procedures in an argument list.


5. Creating Functions in VB.net

By: Steven Holzner : 2010-11-17

Description: Unlike Sub procedures, functions can return values. You use the Function statement to create a function:


6. Passing a Variable Number of Arguments to Procedures in VB.net

By: Steven Holzner : 2010-11-17

Description: Usually, you cannot call a procedure with more arguments than the procedure declaration specifies. When you need an indefinite number of arguments, you can declare a parameter array, which allows a procedure to accept an array of values for an argument. You do not have to know the number of elements in the parameter array when you define the procedure. The array size is determined by each call to the procedure.


7. Specifying Optional Arguments with default values in Procedures in VB.net

By: Steven Holzner : 2010-11-17

Description: You also can make arguments optional in VB .NET procedures if you use the Optional keyword when declaring those arguments. Note that if you make one argument optional, all the following arguments must also be optional, and you have to specify a default value for each optional argument (although you can set them to the keyword Nothing if you wish). You specify a default value with = default_value in the procedure's argument list. Here's an example where I'm making the string argument you pass to a Sub procedure named DisplayMessage optional, and giving that argument the default value "Hello from Visual Basic":


8. Preserving a Variable's Values between Procedure Calls in VB.net

By: Steven Holzner : 2010-11-17

Description: You've written a function named Counter to keep track of the number of times the user clicks a particular button. Each time through a loop, you call the Counter function to increment the count, but when the program ends, it just displays 0 counts. Why? Let's look at the code:


9. Procedure Delegates in VB.net

By: Steven Holzner : 2010-11-17

Description: Sometimes, it's useful to be able to pass the location of a procedure to other procedures. That location is the address of the procedure in memory, and it's used in VB .NET to create the callback procedures. To work with the address of procedures, you use delegates in VB .NET.


10. Properties in VB.net

By: Steven Holzner : 2010-11-17

Description: Visual Basic objects can have methods, fields, and properties. If you've worked with Visual Basic before, you're familiar with properties, which you use to set configuration data for objects, such as the text in a text box or the width of a list box. Using properties provides you with an interface to set or get the value of data internal to an object. You declare properties using Get and Set procedures in a Property statement (and, as you might expect, the syntax has changed from VB6):