Programming With Visual Basic.NET?
Visual Basic .NET is the latest incarnation of Visual Basic. It
is sometimes known as VB7, a misnomer on account of its
incompatibility with VB6: new features and syntax within VB7 mean
that a re-write, instead of a mere port, will be required to keep
the upgrade treadmill going. The new facility of garbage collection
allows for better memory management. There are many new
object-oriented design features and higher levels of type
safety.
1. To program in Visual Basic .NET, you compile straight from
the command line with the .NET SDK, or use Microsoft's Visual
Studio IDE or the open-source SharpDevelop ID.
2. Devising a form by hand will be a challenge if you aren't
familiar with the language, so it's best to use a good form
designer.
3. Start up a Visual Basic .NET IDE and make a Windows
application.
4. Double-click on the form to see the code view. It will be
something like:
Public Class Form1 Inherits
System.Windows.Forms.Form
[Windows Form Designer generated
code]
Private Sub Form1_Load(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
End Sub End Class
5. Put this code in the Form_Load Sub between “Private Sub” and
“End Sub”:
MessageBox.Show("Hello World!")
6. Press F5 or go to the debug menu, then select Start to run
the program. An alert box will appear containing the words “Hello
World!”. Then the main window, empty, will open. Click the “X” of
the title bar to exit.
7. Variables are set like this:
Dim varName As varType
...where Dim is short for
“dimension”, varName is the variable name and varType is the
variable type. Types include integer, char, date and string.
8. Constants are, well, constant.
Const cnstMyConstant As String =
"Bing tiddle tiddle bong"
9. An array contains more than one datum.
Dim MyArray(5) As Integer
...contains five values.
10. Branching is done with If/ElseIf/Else and Select Case.
11. The are several ways to loop. The first is Do...Loop
Until:
Do ' Loop code Loop Until
condition
12. Next is Do ...Loop While:
Do ' Loop code Loop While
condition
13. Then we have Do Until …Loop:
Do Until condition ' Loop code
Loop
14. Do While...Loop:
Do While condition ' Loop code
Loop
15. Next is For:
For a = 1 To 10
' Loop code Next
Visual Basic .NET is one of but a few languages written
specifically for the CLR and the .NET framework. These are its most
basic aspects. The actual commands in your code are just like every
other version of Basic you ever used, making writing in Visual
Basic .NET a very reasonable proposition.