Professional Documents
Culture Documents
/DE#5=#&UHDWLQJ#D#9LVXDO#%DVLF#$SSOLFDWLRQ
In Labs 2, 3, 4, 5, 7, 9, 10, 11 and 14, you will create a loan payment estimate application. You will create
the full application in stages, each stage building on the code created in the previous lab. At the beginning
of each lab, you can either continue with your own files, or start with the files provided for you.
In this lab, you will begin the loan payment estimate application by creating a logon screen.
2EMHFWLYHV
After completing this lab, you will be able to:
To complete the exercises in this lab, you must have the required software. For detailed information about
the labs and setup for the labs, see Labs in this course.
The solution for this lab is located in the <install folder>\Labs\Lab02\Solution folder.
3UHUHTXLVLWHV
There are no prerequisites for this lab.
([HUFLVHV
The following exercises provide practice working with the concepts covered in Chapter 2.
([HUFLVH#4=#&UHDWLQJ#D#/RJRQ#6FUHHQ
In this exercise, you will create a logon screen for the loan payment estimate application. You will start a
new project, rename the form, place controls on the form, and set properties for the controls.
([HUFLVH#5=#$GGLQJ#&RGH#WR#(QDEOH#DQG#'LVDEOH#D#%XWWRQ
In this exercise, you will add code that will enable the OK button only when both a user name and a
password have been entered.
([HUFLVH#6#+2SWLRQDO,=#$GGLQJ#DQ#,FRQ
In this exercise, you will add an icon to a form using the Image control.
Lab 2: Creating a Visual Basic Application
55 ([HUFLVH#4=#&UHDWLQJ#D#/RJRQ#6FUHHQ
In this exercise, you will create a logon screen for the loan payment estimate application. You will start a
new project, rename the form, place controls on the form, and set properties for the controls.
Notes
Page 10
Lab 2: Creating a Visual Basic Application
Note At the top of the Properties window is a drop-down list box of all of the controls on the current
form. It is often easier to use the drop-down list to switch between controls when setting properties on
many different controls.
The resulting form should look something like the following illustration.
End Sub
… 2. Add code to the Click event procedure to display a message box with the current values of the User
Name and Password text boxes:
MsgBox "User Name = " & txtUserName.Text & _
", Password = " & txtPassword.Text
Note The space and underscore in the code above is used to break a single statement across multiple
lines. The ampersand is used to force the combining of two expressions.
… 3. Run the application. Type in a user name and a password, and then click OK. What happens?
Notes
Page 11
Lab 2: Creating a Visual Basic Application
… 4. Type in a different user name and password, and then press ENTER. What happens? Why?
… 5. Close the running application and return to Design mode.
To see answers to the above questions, click this icon.
(CD-ROM displays a hint.)
End Sub
… 3. Run the application. Type in a user name and a password, and then click Cancel. What happens?
… 4. Type in a different user name and password, and then press ESC. What happens? Why?
… 5. Close the running application and return to Design mode.
To see answers to the above questions, click this icon.
(CD-ROM displays a hint.)
Notes
Page 12
Lab 2: Creating a Visual Basic Application
55 ([HUFLVH#5=#$GGLQJ#&RGH#WR#(QDEOH#DQG#'LVDEOH#D#%XWWRQ
In this exercise, you will add code that will enable the OK button only when both a user name and a
password have been entered.
When you write an application, you should minimize the possibility of users making mistakes. One way to
do this is to disable controls when selecting them would cause an error. For example, users shouldn’t be
able to click the OK button on the logon form until they enter a user name and a password.
Note There should be no spaces between quotes. By placing a space between the quotes, the
condition in the If statement checks for the space character in the Textbox and not a zero length string.
… 4. Copy the code from the txtUserName_Change event to the Change event of the txtPassword text
box.
… 5. Save and test your application. Is the OK button enabled?
… 6. Type a user name. Is the OK button enabled? Why?
… 7. Now, type a password. Is the OK button enabled? Why?
To see answers to the questions in steps 5 through 7, click this icon.
(CD-ROM displays a hint.)
Notes
Page 13
Lab 2: Creating a Visual Basic Application
55 ([HUFLVH#6#+2SWLRQDO,=#$GGLQJ#DQ#,FRQ
In this exercise, you will add an icon to a form using the Image control.
Use the Face03.ico file in the <install folder>\Labs\Lab02\Solution folder as the new filename.
… 7. Save and test your application. Which picture is displayed when the application starts?
… 8. Click the image. What happens?
To see answers to the questions in steps 7 and 8, click this icon.
(CD-ROM displays a hint.)
Notes
Page 14