0% found this document useful (0 votes)
75 views8 pages

de#4 #&Uhdwlqj#D#6Lpsoh#$Ssolfdwlrq: 2emhfwlyhv

This document describes exercises for creating a simple application in Microsoft Visual Basic. It includes instructions for adding controls to forms, setting control properties, creating an executable application, and using code examples from help files. The goal is to familiarize students with the Visual Basic development environment and basic programming concepts.

Uploaded by

Edgar Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views8 pages

de#4 #&Uhdwlqj#D#6Lpsoh#$Ssolfdwlrq: 2emhfwlyhv

This document describes exercises for creating a simple application in Microsoft Visual Basic. It includes instructions for adding controls to forms, setting control properties, creating an executable application, and using code examples from help files. The goal is to familiarize students with the Visual Basic development environment and basic programming concepts.

Uploaded by

Edgar Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

31

/DE#4=#&UHDWLQJ#D#6LPSOH#$SSOLFDWLRQ
In this lab, you will learn how to create a simple application in Microsoft® Visual Basic®. Subsequent labs
in this course will explore each of the tasks you try here in more detail.

To see a demonstration of the lab solution, click this icon.


(CD-ROM plays the demonstration, "Lab 1 Solution.")

Estimated time to complete this lab: 45 minutes

2EMHFWLYHV
After completing this lab, you will be able to:

• Identify the elements of the Visual Basic development environment.


• Add controls to forms.
• Use context-sensitive Help.
• Set control properties.
• Create an executable application.

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\Lab01\Solution folder.

3UHUHTXLVLWHV
There are no prerequisites for this lab.

([HUFLVHV
The following exercises provide practice working with the concepts and techniques covered in Chapter 1.

([HUFLVH#4=#8VLQJ#&RQWUROV
In this exercise, you will practice placing controls on a form to become more familiar with the Visual Basic
development environment and controls.

([HUFLVH#5=#&UHDWLQJ#DQ#$SSOLFDWLRQ#ZLWK#&RGH
In this exercise, you will create an application that changes properties of controls while the application is
running.

([HUFLVH#6=#8VLQJ#&RGH#IURP#WKH#+HOS#)LOH
In this exercise, you will locate a code sample in MSDN™ Help and copy it into an application.
Lab 1: Creating a Simple Application

31 ([HUFLVH#4=#8VLQJ#&RQWUROV
In this exercise, you will practice placing controls on a form to become more familiar with the Visual Basic
development environment and controls.

X Start Visual Basic


… 1. Click the Start button, point to Programs, then point to Microsoft Visual Basic 6.0, and then click
Microsoft Visual Basic 6.0.
… 2. Click Standard.exe, and then click Open to start your new project.
A new project with one form should be created.

X Add controls to a form


… 1. Click a control in the Toolbox.
… 2. Place the cross-hair pointer on the form at the desired position for the upper-left corner of the control.
… 3. Click and hold the left mouse button while dragging the pointer to the desired position for the lower-right
corner of the control. Then, release the mouse button.
… 4. Repeat this process with a number of different controls in the Toolbox.

X Get Help on a control


… 1. Click a control you have placed on the form.
… 2. Press F1.
MSDN Help should open to the topic of the selected control.
… 3. Examine the contents of the controls Help topic, and then close the Help window.

X Run the application


… 1. On the Run menu, click Start; or, click the Start button on the Visual Basic toolbar.
Visual Basic should open the form as a program.
… 2. Test the controls on the form.
Notice the controls work as you would expect, even though you haven't written any code.
… 3. Close the running application and return to Design mode, using one of these methods:
a. On the Toolbar, click the End button.
b. On the Run menu, click End.
c. On the system menu, click Close.
d. On the title bar, click the Close button.

Notes

Page 2
Lab 1: Creating a Simple Application

X Remove controls from a form


… 1. Move the mouse pointer to the upper-left corner of the form.
… 2. Click and hold the left mouse button, and then drag the pointer to the lower-right corner of the form.
Then, release the mouse button.
Grab handles will appear on all the controls on the form, indicating that all the controls have been
selected.
… 3. On the Edit menu, click Delete, or press the DELETE key. All selected controls are removed from the
form.

Notes

Page 3
Lab 1: Creating a Simple Application

31 ([HUFLVH#5=#&UHDWLQJ#DQ#$SSOLFDWLRQ#ZLWK#&RGH
In this exercise, you will use the same project used in Exercise 1 and create an application that changes
properties of controls while the application is running.

X Add a TextBox and a Label control to the form and align them horizontally
… 1. Add a TextBox control to the form.
… 2. Add a Label control to the form, and position the Label to the right side of the TextBox.
… 3. Click on the form and drag a box around both controls to select them.
… 4. Click the control on the form that you want the other controls to align to.
The control's grab handles should change to a solid color.
… 5. On the Format menu, click Align, and then click Tops to horizontally align the controls to the last
selected control.

X Set control properties at design time


… 1. Click on the form to deselect the other controls, and then select the Label control on the form.
… 2. In the Properties window, change the Caption property to “My Label.”
… 3. Select the TextBox control.
… 4. In the Properties window, change the Text property to “My TextBox."

X Change control properties at run time


… 1. Double-click the TextBox control on the form.
The Code Editor window will open showing the Text1_Change event procedure.
… 2. Add the following statement to the body of the procedure:
Label1.Caption = Text1.Text

This code statement changes the caption of the Label control to the text the user types in the TextBox
control.
… 3. Run the application and type some text in the text box. Note what happens.
… 4. Close the application and return to Design mode.

X Save the project


… 1. On the File menu, click Save Project.
… 2. When prompted to save the form, change the destination folder to <install folder>\Labs\Lab01, keep the
default name of Form1, and click Save.
… 3. When prompted to save the project, change the destination folder to <install folder>\Labs\Lab01, keep
the default name of Project1, and click Save.

Notes

Page 4
Lab 1: Creating a Simple Application

X Create an .exe file


… 1. On the File menu, click Make Project1.exe to make the executable file. Make sure that the destination
folder is <install folder>\Labs\Lab01.
… 2. In the File name text box, type Firstapp and then click OK. Visual Basic compiles the current project
and creates an executable file that can be run directly from Microsoft Windows®.
… 3. Exit Visual Basic and save changes if prompted.

X Run the .exe file


… 1. Click the Start button, point to Programs, and then click Windows Explorer.
… 2. In Windows Explorer, navigate to the <install folder>\Labs\Lab01 folder.
… 3. Run the application you just created by double-clicking on the Firstapp executable file.
… 4. Test the application by typing some text in the text box.
… 5. Close the application.

Notes

Page 5
Lab 1: Creating a Simple Application

31 ([HUFLVH#6=#8VLQJ#&RGH#IURP#WKH#+HOS#)LOH
In this exercise, you will locate a code sample in MSDN Help and copy it into an application.

X Open Project1
… 1. Start Visual Basic.
… 2. Click the Recent tab, select Project1, and then click Open.
… 3. If the form is not visible, select it in the Project Explorer window and click View Object.

X Use context-sensitive Help


… 1. Double-click anywhere on the form, outside of the TextBox or Label control.
The following lines of code will appear in the Code Editor window:
Private Sub Form_Load()

End Sub

… 2. In the Code Editor window, select MouseMove from the Procedure drop-down list box.
The contents of the Code Editor window will change to the following:
Private Sub Form_MouseMove(Button As Integer, Shift As _
Integer, X As Single, Y As Single)

End Sub

… 3. Type FillColor between the Sub and End Sub lines.


… 4. Highlight the word FillColor, and press F1.
MSDN Help will display the FillColor Property Help topic.

X Copy example code from MSDN Help and paste it into a Visual Basic application
… 1. Click the Example jump topic at the top of the Help window.
A Help window should open with an example of how to use the FillColor property.
… 2. Select the three lines of code between the Sub and End Sub statements.
… 3. Right-click anywhere on the selected text and click Copy to copy the selected lines to the Clipboard.
… 4. Close the MSDN Help window.
You should now be back in the Code Editor window, displaying the Form_MouseMove event
procedure. If not, in the Code Editor window, click Form on the Object list and MouseMove from the
Procedure list to move to the Form_MouseMove event procedure.
… 5. Highlight the FillColor command in the procedure.

Notes

Page 6
Lab 1: Creating a Simple Application

… 6. On the Edit menu, click Paste to paste the copied code into the Form_MouseMove event procedure.
The resulting event procedure should look similar to this:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
' Choose random FillColor
FillColor = QBColor(Int(Rnd * 15))
' Choose random FillStyle
FillStyle = Int(Rnd * 8)
' Draw a circle
Circle (X, Y), 250
End Sub

X Save and test your application


… 1. On the File menu, click Save Project to save the changes to the project and the form in <install
folder>\Labs\Lab01.
… 2. Run the application and move the mouse pointer around on the form. What happens?
… 3. Close the application.
To see the answer to the question in step 2, click this icon.
(CD-ROM displays a hint.)

Notes

Page 7
This page intentionally left blank.

You might also like