Introduction to
Visual Basic Programming

The following exercises require you to start Visual Basic, load a project that will allow you to experiment with the Visual BASIC language. For homework, write up the answers to the questions.


Starting Visual Basic

Find the Visual Basic icon and double click (nothing new). See page 10 of the VB QuickLook manual. Also note the various number of windows (page 11):

Further explanations of these windows are found on pages 12-15.


Loading and running a program/project

To load a project in which you can experiment with the Visual Basic language, do the following:
From the File menu click on Open Project…
and load the project found at P:\INTRO\VBASIC\STARTER.MAK

Now click on the View Form button to see an interface set up to run simple programs. The interface can also let you begin to experiment with input and output through the form's components.

Click on the View Code button to display modules of code. You need to find the code for object Display and procedure Click. You may erase all the code that is there between the first and last lines. Keep the first and last lines intact. The Basic programs that you are to enter and try out are listed below.


A first Basic program

Sub Display_Click ()
REM - a first program with simple printing
PRINT "Hello, World"
PRINT "The sum of 3+5=";3+5
End Sub

To run the program, click on the run button, press F5, or click on Run, then Start from the menu. The form should appear (without all the alignment dots). Click on the Display Results button to cause the code you put into the Display_Click module to be executed. If everything is correct you should see

Hello, World
The sum of 3+5= 8

displayed at the top left of the form.

Q1: What happens if you click on the Display Results button again?

Q2: What happens if you click on other places on the form?


A program with errors

Enter the following program exactly as given and see what errors you get.

Remark: a program with errors
print "simple addition'
let 2s = 2 + 3
print "the sum is"; 2s

Q3: What's wrong with using Remark for remarks?

Q4: What did Visual Basic do to the wrong type of quote on the first print?

Q5: What did you have to do in the let statement to have it accepted?

Q6: How did your change in the let statement affect the last print or vice versa?


A second program

You need to access a textbox when you want to get a value from the user. If the textbox is called InputTxt, then the string of characters entered in the textbox is referred to InputTxt.text. If you want to compute with its numeric value use Val(InputTxt.text).

When you want to output a string to a textbox called OutputTxt you can just assign the new value to OutputTxt.text.

Q7: When the Calculate button is clicked how is the value in the Input textbox transformed to the Output textbox?

Revise the program code in module Calculate_Click that will treat the value in the Input textbox as the number of hours worked and multiply it by $8.50 per hour to get gross pay, subtract 15% in taxes and display the net pay in the Output. Print the gross pay in the form using a print statement.


Print your program code

Be sure you have the form design as the active window.

Go to File then Print… menu items and check off the code box and then click on OK.

Turn in this listing along with your answers to the questions.