Upload
harrystyles12
View
221
Download
0
Embed Size (px)
Citation preview
8/11/2019 Visual Basic Lesson 2 and 3
1/24
8/11/2019 Visual Basic Lesson 2 and 3
2/24
Steps in Writing Visual Basic Projects
1. Create the user interface.2. Set the properties.
3. Write the Basic code.
8/11/2019 Visual Basic Lesson 2 and 3
3/24
8/11/2019 Visual Basic Lesson 2 and 3
4/24
Step 2 Set the properties.
Toolbox
FORM
PROPERTYcharacteristic of an object.(color, size, background)
8/11/2019 Visual Basic Lesson 2 and 3
5/24
PROPERTIES WINDOWdisplays attribute of thecurrently selected component (form/control).
PropertyName
PropertyValue
8/11/2019 Visual Basic Lesson 2 and 3
6/24
Name property willbe used to refer to the
control in the Visual
Basic code.
Caption property tells what the user
will see on the form
8/11/2019 Visual Basic Lesson 2 and 3
7/24
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 andother special characters
Examples:
Kagitingan 3KagitinganKalayaan_3 _Kalayaan3 Kamalayan2012 Katarungan 2012
Katarungan! Kagitingan_&2012
8/11/2019 Visual Basic Lesson 2 and 3
8/24
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:
lblKagitingancmdPrintTheForm
8/11/2019 Visual Basic Lesson 2 and 3
9/24
8/11/2019 Visual Basic Lesson 2 and 3
10/24
-joining strings of text
Use an ampersand (&) precededand followed by a space between
two strings
8/11/2019 Visual Basic Lesson 2 and 3
11/24
8/11/2019 Visual Basic Lesson 2 and 3
12/24
Steps in Writing Visual Basic Projects
1. Create the user interface.2. Set the properties.
3. Write the Basic code.
8/11/2019 Visual Basic Lesson 2 and 3
13/24
-the statement that carriesout the action when the
event is triggered.
End
lblDisplay.Caption=Hello World
PrintForm
- the users action
cmdDisplay_Click
cmdCalculate_DblClick
8/11/2019 Visual Basic Lesson 2 and 3
14/24
- adding a code in anevent
8/11/2019 Visual Basic Lesson 2 and 3
15/24
EVENT DESCRIPTION
Activate This event occurs when forms get a focus.
Click This event occurs when the user click anywhere on the formor control.
Initialize This event occurs when the form is first generated.
Load This event occurs when the form is loaded into thecomputers memory and displays on the screen.
Dblclick This event occurs when the user double-clicks the form orcontrol.
Deactivate This event occurs when another form gets the focus.
Unload This event occurs when the form is terminated from thecomputers 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.
8/11/2019 Visual Basic Lesson 2 and 3
16/24
- a section in the code window
that holds assignmentstatements for a control toperform a specific task or action.
Private Sub cmdPushMe_Click ()
lblDisplay.Caption=Hello World
End Sub
8/11/2019 Visual Basic Lesson 2 and 3
17/24
8/11/2019 Visual Basic Lesson 2 and 3
18/24
- displays the name of the control
that will trigger the event
- specifies the type of event for thecontrol
8/11/2019 Visual Basic Lesson 2 and 3
19/24
8/11/2019 Visual Basic Lesson 2 and 3
20/24
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
8/11/2019 Visual Basic Lesson 2 and 3
21/24
8/11/2019 Visual Basic Lesson 2 and 3
22/24
8/11/2019 Visual Basic Lesson 2 and 3
23/24
Private Sub cmdCalculate_Click ()
Calculate the price and discountDim 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 variablesintQuantity = Val(txtQuantity.Text)
curPrice = Val(txtPrice.Text)
Calculate valuescurExtendedPrice = intQuantity * curPrice
curDiscount = curExtendedPrice * curDiscountRate
curDiscountedPrice = curExtendedPricecurDiscount
End Sub
8/11/2019 Visual Basic Lesson 2 and 3
24/24
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