Programming Tutorials

VB.net Tutorials

1. Changes in Controls from VB6 to VB.net

By: Steven Holzner : 2010-11-17

Description: In fact, the Caption property no longer exists; it's been replaced by the Text property. There are other changes in controls from VB6 as well—and plenty of them. I'll take a look at a number of general points here to start us off.


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


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


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


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


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


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


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


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


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