Sunteți pe pagina 1din 15

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?
Form at Run Time
What makes a program work?
Accessing the Code Window
• Clicking on the View Code button on the
Project Explorer Window
• Selecting a Control and Pressing F7
• Double-Clicking on a Control
Parts of the Code Window
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

Private Sub cmdYes_Click ()

lblText.Caption = “Welcome!!!”

End Sub
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
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

S-ar putea să vă placă și