Cyber Institute of Technology

 

 

Visual Basic 2005 Mini Tutorials

MT-1.           Write a simple program in Visual Basic 2005.

In this mini tutorial, we will design a simple program that allows a user to click on a button, causing the program to respond with a welcome message, “Welcome to Visual Basic 2005!”

 

Tutorial objectives

This tutorial covers the following concepts:

  1. How to open Visual Studio  2005 (or Visual Basic 2005 Express Edition)
  2. How to create a new project using Visual Basic 2005
  3. How to add the following control instances to a form:
    1. Button instance
    2. TextBox instance
    3. LinkLabel instance
  4. How to add code to the Click_Button event handler
  5. How to display text in a textbox
  6. How to run the program
  7. How to close the project
  8. How to exit Visual Studio 2005

 

Step 1

 

When you complete the program and run it, the user interface should look similar to the following screenshot.

 

 

 

 

Step 2

 

When  you click the Welcome button, the program displays a welcome message in the textbox, similar to the following

 

 

Ready to design and run the program? Let us get started.

 

Step 3

If you have not yet installed yet Visual Basic 2005 Express Edition, now is a good time to install. You can download it free of charge, if you act before  Nov. 7, 2006.

 

 

 

 

 

Step 4

 

Start Visual Basic 2005 from the start menu, All Programs, then Visual Basic 2005.

 

Step 5

 

Wait for the Integrated Development Environment (IDE) to come up. It should look similar to the following screenshot.

 

 

 

 

Step 6

 

Using the left mouse button, Go to File then select New Project…

 

 

 

Step 7

 

A dialog box pops up asking for the project name.

a.       Make sure to highlight Windows Application under Visual Studio installed templates.

b.       The IDE suggests WindowsApplication1  as the default name for the project. Change this to a more meaningful name like SimpleProgramVB2005, then click OK

 

c.           After a few seconds, you will get a window similar to the screenshot below.

Form1, in the middle area, is where you drag and drop controls using the Toolbox, which is located just to the left.

 

 

 

 

 

Step 8

 

Using your left mouse button, click and hold on Button in the Toolbox and drag it anywhere on the surface of Form1, then let go of the mouse. The button be called Button1. The first instance you create of a control is called ControlName1, the second one is called ControlName2, and so on.

 

 

 

 

Step 9

 

Next, drag and drop a Textbox to Form1. The textbox has the  default name Textbox1.

 

 

Step 10

 

Using your left mouse button, you can move these two controls, Button1 and Textbox1, anywhere on the surface of Form1.  

 

 

 

Step 11

 

To resize a control, click on it then use the handle to resize it. The textbox has two handles; the button has eight handles.

 

Step 12

 

Position Button1 just below Textbox1, as shown in the following screenshot.

 

 

 

Step 13

 

Next,  change the default properties for Form1, Button1, and Textbox1. The properties window should be located at the lower right hand corner. If you do not see it, select Window -> Reset Window Layout from the IDE menu. This will reset the IDE windows to their original configurations, which should look similar to the screenshot below.

 

Step 14

 

Change the name of Form1 to  Visual Basic 2005 Simple Application.

a.       To select Form1, click anywhere on its surface, except on the two controls.

b.       In the properties window, look for a property called Text. To its right, the name should be Form1. Double-click on it to select it.

c.       Type over the name Form1 to change it to Visual Basic 2005 Simple Application  and hit enter.

d.       The text on the form should now read Visual Basic 2005 Simple Application

 

 

 

 

Step 15

 

Change the text  of Button1  to  Welcome

a.       To select button1, click on it.

b.       In the properties window, look for the Text property and change its value from Button1 to Welcome. The text on the button should now read  Welcome

 

Step 16

 

Change Finally, verify that the text of Textbox1 is empty so that when the program runs, the textbox will be empty.

 

NOTE:

Note that we are not changing the (Name)  property of the controls, we are only changing the Text property.  The (Name)  is what we use to refer to the control within our code. The Text property holds the value that gets displayed to the user.

 

Step 17

 

We are not yet done with the design of the program, but let us execute the program to see what we have. It is a good programming practice to do a little bit of development, then execute your program to check if you are on the right track, then continue with your development.

 

At this point, when you click on the button Welcome, nothing happens. Why? Because we have not yet entered the code behind the Welcome button to make it display the message in the textbox.

 

 

 

Step 18

 

Exit the form by clicking on the “X”

 

Step 19

 

Double-click on the Welcome button to enter the code for it. This should take you directly to where you enter your code, as shown in the screenshot below. In this example, when the user clicks the Welcome button, the program responds by displaying the message “Welcome to Visual Basic 2005!” in the textbox.

 

 

 

 

 

Step 20

 

Click on the Tab that says SimpleProgramVB2005.vb [Design] at the top of the designer area. Notice that nothing visually has changed on the form.  

 

Step 21

 

Finally, add a “close this window” link, so that the user can close the form, rather than click on the “X” of the form.

 

Drag and drop an “LinkLabel” on the form, just below the Welcome button. A LinkLabel1 is created.  Change its Text property to LinkLabelCloseWindow.

 

Step 22

Congratulations! You are done. Execute the program and make your modifications to learn more about Visual Basic 2005.

 

Comments? Feedback? Questions? Please let us know. Thank you!

 

Visual Basic 2005 Mini Tutorials