Hello World Program

In this lesson you will write your first Visual Basic program. There are two main parts:

1. The visual programming step - Creating the objects.
2. Writing the code for the visual objects.

When you are finished you will have a simple program that looks like this:

When you click on the Display Hello button it will put the "Hello World" text in the text box. When you click on the Clear button it will remove the text from the text box. Clicking on the Exit button will close the program.

STEP 1: VISUAL PROGRAMMING

1. Open Visual Basic Express 2008. To do so go to Start, Programs, Programming, Visual Basic Express 2008.
 

2. Start a new project by going to File, New Project.
3. Choose a Windows Forms Application, name it helloWorld and click OK.
4. Save the project by going to File, Save All, or click on the Save All icon.

* Clicking on an object allows you to change its properties.
* The properties of an object define how the object looks and behaves.

5. Change the Text property of the form to The Hello Program.

 

6. Change the BackColor to blue.

Save again by choosing Save All.

7. Add an Exit button to the form. Double-click the icon for the Button in the toolbox window. A button will appear on the form.
8. Make sure the button is selected and change its Name property to btnExit. This is the name that the button will be referred to in the code that we are about to write. Always start a Button name with btn.
9. Change the button's Text property to Exit. This is the text that shows up on the button.
10. Change the button's Font property to your preference. Drag the button to the bottom, center of the form. Resize as desired.

Save again by choosing Save All.

11. Add the other buttons to the form, and change the properties as shown below:

Object

Property Setting
Button Name btnHello
  Text Hello
  Font and size Same as Exit button.
Button Name btnClear
  Text Clear
  Font and size Same as other buttons.
12. Add a TextBox to the form, and change the properties as shown below:

Name - txtDisplay     Always start a TextBox name with txt.
TextAlign - Center
MultiLine - True
Font and size - Same as buttons.

Save again by choosing Save All.

Go to Step 2: Attaching the Code to the Objects