VB.net Tutorials

11. Understanding Scope in VB.net

By: Steven Holzner : 2010-11-17

Description: The scope of a variable or constant is the set of all code that can refer to it without qualifying its name. A variable's scope is determined by where the variable is declared. It's usually a good idea to make the scope of variables or constants as narrow as possible (block scope is the narrowest). This helps conserve memory and minimizes the chances of your code referring to the wrong item. I'll take a look at the different kinds of scope in VB .NET here.


12. 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):


13. 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.


14. 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:


15. 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":


16. 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.


17. 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:


18. 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.


19. 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:


20. 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