[go: up one dir, main page]

0% found this document useful (0 votes)
22 views6 pages

Self - Learning Module - 2 - Q4

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)
22 views6 pages

Self - Learning Module - 2 - Q4

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/ 6

Computer science

02

Managing a Project

Understand the different event procedures


used in coding in visual basic.

Specific Objectives
1. Identify the different event procedure used in writing Visual Basic codes.
2. Understand the property window of Visual Basic based on the control
used.
3. Run and observe simple Visual Basic program.
4. Create Visual Basic project.

Materials
 Microsoft Word
 Computer

Lesson
Event Procedure

Visual Basic is an event-driven language. It is governed by an event


processor. If the event is detected, the project finds a series of instructions
related to that event, called event procedure. The procedure is executed, then
program control is returned to the event. Event procedures are the steps taken
when we do the actual computer programming.

1
Some of the main user actions that execute events in a program
 Starting the program
 Press a key
 Click the mouse
 Move the mouse
 Close the program

Events Common to Many Controls


EVENT ACTIONS
Change The user changes the textbox or combobox.
Click The user clicks an object with the primary mouse.
DblClick The user double-clicks an object with the mouse.
DragDrop The user drags a control to another place.
DragOver An object is dragged over a control.
GotFocus An object receives the focus.
KeyDown A key is pressed while an object has the focus.
KeyPress A key is pressed and released while an object has the focus.
KeyUp A key is released while an object has the focus.
LostFocus The focus has left an object.
MouseDown A button is pressed while the pointer is over an object.
MouseMove The cursor is moved over an object.
MouseUp The button is released while the pointer is over an object

Event Procedure begins with the statement Private Sub and ends with
the End Sub.

EVENT PROCEDURE DESCRIPTION


Form_Load It is called once when form is loaded into
memory. Place where to do initialization in the
code for any part of the form with the controls
and variables.
Form_Paint It is called everytime the form needs to be
repainted. Repainting is the process of updating
the form image on the screen.
Form_Click It is called when the user clicks an area of the
form not covered by a control.
buttonname_click It is called when the user clicks a button.

Working with Controls and Objects

Controls allow you to trigger events or perform actions. These are the
building blocks of Visual Basic application. To add controls on the form, double-

2
click the control you want to add or draw the control by clicking the control and
then drag the mouse around the area where you want to put the control.

To use the Command Button


1. Select the CommandButton from the toolbox.
2. Click and draw the button on the form. Resize it depending on how or
where you want it to appear.
3. Change the Name of the CommandButton to cmdTinboy.
Change the Caption to Tinboy.
4. Select the CommandButton again from the toolbox.
Draw the CommandButton in the form.
5. Change the Name of the CommandButton to cmdTin.
Change the Caption to Tin.

6. Double-click the Tinboy CommandButton. This brings you to the Code


Editor window.
Type the following:
cmdTin.Enabled = True
cmdTinboy.Enabled = False
7. Click the X button of the Code Editor window.
8. Double-click the Tin CommandButton.
Type the following code inside the Code Editor window.
cmdTin.Enabled = False
cmdTinboy.Enabled = True
9. Run the program by pressing F5 or by clicking the Run menu then Run
Macro. Observe the two CommandButtons.

3
To use the label control
1. Select Label from the toolbox.
2. Draw the label on the previous form.
3. Change the label’s property Name to Jhennylabel.
4. Change the property BorderStyle to 1-frmBorderStyleSingle.
5. Make changes on the code for each CommandButton.
Type the following codes:
for Tinboy CommandButton:
cmdTin.Enabled = True
cmdTinboy.Enabled = False
Jhennylabel.caption = cmdTinboy.caption

for Tin CommandButton:


cmdTin.Enabled = False
cmdTinboy.Enabled = True
Jhennylabel.caption = cmdTin.caption
6. Run the program by pressing F5 or click button. Observe.

To use the TextBox


1. Make a new project.
2. Select TextBox from the toolbox.
3. Change the property Name to txtFrancis.
4. Set the property Multiline to True. (This property allows you to type to
the next line).
5. Set the property Scrollbars to 3-frmScrollBarsBoth.
6. Run the program. Type a list inside the TextBox and observe the
scrollbars.

To use Frame and Option Buttons


1. Select Frame in the toolbox and draw in the form.
Change the property Name to fraStatus.

4
Change the property Caption to Civil Status.
2. Select Option button. Draw inside the frame.
Change the property Name to optSingle.
Change the property Caption to Single.
3. Select another Option button. Draw inside the frame.
Change the property Name to optMarried.
Change the property Caption to Married.
4. Select Frame again and draw on the form.
Change the property Name to fraChildren.
Change the property Caption to Number of Children.
5. Select TextBox in the toolbox and draw inside the Number of Children
frame.
Change the property Name to txtChildren.
6. Double-click the Single option box, then type the following code.
fraChildren.Enabled = False
txtChildren.Enabled = False
7. Click the X button to exit in the Code Editor window.
8. Double-click the Married option box, then type the following code:
fraChildren.Enabled = True
txtChildren.Enabled = True
9. Run the program by pressing F5 or click button. Observe the frame and
textbox of Number of Children frame.

In the Single option, the Number of


Children frame is not accessible.

In the Married option, the Number


of Children frame is accessible.

EXERCISES

BASIC

1. Make an application that can add two numbers. The answer must be
displayed inside the textbox.
2. Make an application that can compute the average of three given
numbers.

5
Closure
A. Please check the box if you can do it already.

• I can explain what are the different event procedures;


• I can manipulate and use the controls of Visual Basic properly.

B. If you have questions in mind, please use the space below to address it.
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________

References
Amoto Jr., Tito B. Visual Basic 6.0. Quezon City, Book Craft Publishing Co., Inc.,

2001.

https://docs.microsoft.com/en-us/office/vba/language/reference/user-
interface-help/toolbox

https://upload.wikimedia.org/wikipedia/commons/b/b8/Visual_basic_6.0.pdf

https://www.vbtutor.net/lesson1.html

You might also like