Hello World Example
Visual Basic is a graphical programming environment that allows for rapid prototyping of designs. Visual Basic is an event driven environment, meaning all controls, objects, or widgets that you place in a window or form come with their own events that can be fired either automatically or by some user action, such as a mouse click or key press.
These instructions will build an example program that looks like this:

|
|
Download the code by clicking on the Zip file. |
Instructions for Creating the Example:
Important Files to Note: HelloWorld.sln is the project file and running it will open up your project in Visual Studio. Form1.vb contains code for a form or window. Form1.resx contains information about the design of a form, e.g., which widgets a form uses and where they're placed. The bin folder contains an executable for your project after compiling.

The Toolbox lets you select widgets or objects to place on a form. You can see all the widgets and expand the toolbox by clicking on the Toolbox icon. The Solution Explorer is a listing of all forms or code modules that belong to your project. The Properties toolbar allows you to customize various properties for each widget.


| Button1 | Label1 | Label2 | Label3 | |
| Name | btnCheck | lblName | lblAddress | lblAge |
| Text | Check User | Name | Address | Age |
| TextBox1 | TextBox2 | |
| Name | txtName | txtAddress |
| Text | <make it empty> | <make it empty> |
| TrackBar1 | |
| Name | trkAge |
| Minimum | 0 |
| Maximum | 30 |
| Value | 15 |
Your user interface should look like this so far:





Private Sub btnCheck_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
' check the text property of txtName
If txtName.Text = "Carman" Then
MsgBox("You rock!", vbOKOnly, "Name
Validation")
Else
MsgBox("Error", vbCritical, "Name
Validation")
End If
' check the value property of trkAge
If trkAge.Value < 5 Then
MsgBox("Youngin'", vbOKOnly, "Age
Validation")
ElseIf trkAge.Value >= 5 And trkAge.Value < 18 Then
MsgBox("How's school going?",
vbOKOnly, "Age Validation")
Else
MsgBox("Start planning your life...",
vbOKOnly, "Age Validation")
End If
' reset our controls' properties
txtName.Text = ""
txtAddress.Text = ""
trkAge.Value = 0
End Sub
Private Sub frmMain_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' this subroutine runs when your form
first appears
' we will change some properties of our controls at startup
' to access a control's property, type the name of the
control, then a period, and
' finally the property's name
txtName.Text = ""
txtAddress.Text = ""
trkAge.Value = 15
End Sub

To run your code, go to the Debug menu and choose Start.

If you get a compile error that says "Sub Main" not found. Right click on your project name and select Properties from the context menu.

In the dialog window that appears, choose frmMain as the startup object.

Clicking in the left margin of your code will place a Breakpoint. This means your code will stop when it gets to this line. The highlighted line in the picture below contains a breakpoint.

When your code stops, you can check out what values are contained in objects and variables to debug the current state of your program.
Pressing the F11 key or choosing Step Into from the Debug menu will move to the next executing line of code. Step Into will allow you to go into functions and subroutines should a line of code call a different function or subroutine.
Pressing the F10 key or choosing Step Over from the Debug menu will move to the next executing line of code. The difference between Step Over and Step Into is that Step Over will not go into functions or subroutines if they are called.

