0% found this document useful (0 votes)
118 views

The Code Window: Computer II: Programming With VB6

This document discusses the code window in VB6 and programming with controls. It explains how to access the code window, the parts of the code window like the object list and event list, and provides examples of code for event procedures. Key terms like controls, procedures, private sub, and end sub are defined. The document encourages good programming practices like indenting code and using the autocomplete feature when setting properties. It includes a hands-on example of adding code to set the caption property of a label when buttons are clicked.

Uploaded by

ephraim_q
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

The Code Window: Computer II: Programming With VB6

This document discusses the code window in VB6 and programming with controls. It explains how to access the code window, the parts of the code window like the object list and event list, and provides examples of code for event procedures. Key terms like controls, procedures, private sub, and end sub are defined. The document encourages good programming practices like indenting code and using the autocomplete feature when setting properties. It includes a hands-on example of adding code to set the caption property of a label when buttons are clicked.

Uploaded by

ephraim_q
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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?
frmEntry

lblPrompt

lblText

cmdYes cmdNo
Form at Run Time

Output when Output when


cmdYes is clicked cmdNo is clicked
What makes a program work?

Code Window
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 Event List
Box 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
the following if  Control Event
Private Sub cmdYes_Click ()
cmdYes is
Clicked 

 lblText.Caption =
“Welcome!!!”
Name of Property Setting

Control
 Translation: Change the

caption property of lblText
to 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
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

You might also like