Sei sulla pagina 1di 24

Steps in Writing Visual Basic Projects

1. Create the user interface.


2. Set the properties.
3. Write the Basic code.
Step 1 - Create the user interface.
Toolbox
FORM
Step 2 Set the properties.
Toolbox
FORM
PROPERTY characteristic of an object.
(color, size, background)
PROPERTIES WINDOW displays attribute of the
currently selected component (form/control).
Property
Name
Property
Value
Name property will
be used to refer to the
control in the Visual
Basic code.
Caption property
tells what the user
will see on the form
Naming Rules and Conventions for Objects
The Naming Rules
- Begin with a letter (40 characters in length)
- Name can contain letters, digits and
underscores only
- Do not include a space, punctuation marks and
other special characters
Examples:
Kagitingan 3Kagitingan
Kalayaan_3 _Kalayaan3
Kamalayan2012 Katarungan 2012
Katarungan! Kagitingan_&2012

Naming Rules and Conventions for Objects
The Naming Conventions
- Begin the name with a lowercase three-letter prefix
(three-letter prefix identifies the object type)

- Capitalize the first character after the prefix
- For names with multiple words, capitalize each
word in the name.
Examples:

lblKagitingan
cmdPrintTheForm
OBJECT CLASS PREFIX EXAMPLE
Form frm frmDataEntry
Command button cmd cmdExit
Text box txt txtName
Label lbl lblTotal
Option button opt optRed
Check box chk chkItalic
Frame fra fraSelection
Horizontal scroll bar hsb hsbRate
Vertical scroll bar vsb vsbTemperature
Image img imgLogo
Picture box pic picLandscape
Combo box cbo cboBookList
List box lst lstIngredients
Shape shp shpBox
List of Object Prefixes
- joining strings of text
Use an ampersand (&) preceded
and followed by a space between
two strings
Steps in Writing Visual Basic Projects

1. Create the user interface.
2. Set the properties.
3. Write the Basic code.
- the statement that carries
out the action when the
event is triggered.
End
lblDisplay.Caption=Hello World
PrintForm
- the users action
cmdDisplay_Click
cmdCalculate_DblClick
- adding a code in an
event
EVENT DESCRIPTION
Activate
This event occurs when forms get a focus.
Click
This event occurs when the user click anywhere on the form
or control.
Initialize
This event occurs when the form is first generated.
Load
This event occurs when the form is loaded into the
computers memory and displays on the screen.
Dblclick
This event occurs when the user double-clicks the form or
control.
Deactivate
This event occurs when another form gets the focus.
Unload
This event occurs when the form is terminated from the
computers memory.
Resize
This event occurs when the user changes the size of a form.
Change
This occurs when the user changes the text inside a textbox.
- a section in the code window
that holds assignment
statements for a control to
perform a specific task or action.
Private Sub cmdPushMe_Click ()

lblDisplay.Caption=Hello World

End Sub
Private Sub cmdPushMe_Click ()

lblDisplay.Caption=Hello World

End Sub
PRIVATE the procedure is
solely for the selected object or
form.
SUB indicates the
beginning of the event
procedure.
the control that will
do the event.
the event that
should occur to the
object or control
indicates the
termination of the
event procedure.
- displays the name of the control
that will trigger the event
- specifies the type of event for the
control
Private Sub cmdPushMe_Click ()
Display the caption Hello World in the label
lblDisplay.Caption=Hello World
End Sub
Private Sub cmdExit_Click ()
Exit the project
End
End Sub
Private Sub cmdCalculate_Click ()

Calculate the price and discount
Dim intQuantity As Integer
Dim curPrice As Currency
Dim curExtendedPrice As Currency
Dim curDiscount As Currency
Dim curDiscountedPrice As Currency
Const curDiscountRate As Currency = 0.15

Convert input values to numeric variables
intQuantity = Val(txtQuantity.Text)
curPrice = Val(txtPrice.Text)

Calculate values
curExtendedPrice = intQuantity * curPrice
curDiscount = curExtendedPrice * curDiscountRate
curDiscountedPrice = curExtendedPrice curDiscount

End Sub
Private Sub cmdExit_Click ()

Exit the project

End

End Sub
Date: August 2, 2012
Programmer: (your name)
Description: This project demonstrates the use of
variables, constants, and calculations

Potrebbero piacerti anche