The Code Window Computer II: Programming with VB6
What have we learned so far? • • • •
Saving Projects properly Placing Controls on the Form Changing the Name Property of a Control Setting other properties of a Control
What do you think are the names of these controls? frmEntry lblPrompt lblText
cmdYes
cmdNo
Form at Run Time
Output when cmdYes is clicked
Output when cmdNo is clicked
What makes a program work?
Code Window
Accessing the Code Window • Clicking on the View Code button Project Explorer Window • Selecting a Control and Pressing F7 • Double-Clicking on a Control
on the
Parts of the Code Window Object List Box
Event List Box
Code Area
Object List Box • Lists the objects or controls in the form
Event List Box • Lists all events or procedures related to the selected control
Terms to Remember • Controls – also called objects • Procedure – events; declarations that are performed when you do an action to an object • Private – indicates that the procedure will only take place inside the form • Sub – stands for subprocedure • Private Sub – start of a subprocedure • End Sub – end of a sub procedure
Sample Code Translation: Do Name of Event the following if Control Private Sub cmdYes_Click () cmdYes is Clicked lblText.Caption = “Welcome!!!” Name of
Control
End Sub
Property
Setting
Translation: Change the caption property of lblText to Welcome!!!
Good Programming Practices To improve the readability of your code: • Indent the lines between the Private Sub and End Sub • Places spaces between lines
Good Programming Practices To be more accurate in creating subprocedures • Double-click the control (this automatically types the Private Sub and End Sub) • When typing the Property, choose from the list box that comes out after typing the first letters then press Space
Hands On 3: Entry frmEntry lblPrompt lblText
cmdYes
cmdNo
Place the following in the Code Window then modify the settings as you see fit
Private Sub cmdNo_Click() lblText.Caption = "Goodbye! See you soon!" End Sub
Private Sub cmdYes_Click() lblText.Caption = "Welcome!!!" End Sub