Introduction to Computing Dr. Nadeem A Khan
Lecture 7
Announcement ► New TAs Harris Mukarram Mubashir Amjad Hunain ► Visit the Website for their office hours
How to make our user-interface do something?
Visual Basic Events ► Event : Action taken by the user e.g. Clicking a Control Double Clicking a Control Getting Focus Losing Focus etc. etc.
Visual Basic Events (Contd.) ► Naming of Events Clicking a Command Button 1 ► Command1_Click Double Clicking a Picture Box 2 ► Picture2_DblClick Text box 1 gets Focus ► Text1_GotFocus Text box 1 loses Focus ► Text1_LostFocus
Visual Basic Events (Contd.) ► Names of events => objectName_event ► Events are pre-defined
Event Procedure ► Event Procedure: block of code to be executed when an event occurs ► General form Sub objectName_event() statements End Sub
Event Procedure (Contd.) ► E.g: Sub Command1_Click() statements End Sub Sub Text1_GotFocus() statements End Sub
Statements?
VB Statements ► Statements to change the properties of an object the general form: the general form: Let objectName.property = setting
Statements (Contd.) Let objectName.property = setting E.g: Let Text1.FontSize = 12 Let Text1.FontBold = TRUE Let Text1.Text = “ ”
Event Procedure (Contd.) ► Event procedure – general form Sub objectName_event() statements End Sub ► Example Sub Command1_Click() Let Text1.text = “” Let Text2.text=“Hello” End Sub
Viewing Code Margin Indicator Bar Procedure View Full Module View Object Box Procedures List Box Split Bar
Methods ► Another category of statements based on methods
Methods (Contd.) ► E.g: Picture1.Cls Clears Picture1 Picture Box Picture1.Print 3 Prints ‘3’ in the Picture1 Picture Box Prints ‘3’ in the Picture1 Picture Box
Methods (Contd.) ► General form of these statements => objectName.Method parameters (if any)
The Print Method ► Picture1.Print m? ► Picture1.Print m; ? ► Picture1.Print m; n; r ? m, n, r are numbers e.g. 3, 5.2 m, n, r are numbers e.g. 3, 5.2
Numbers ► Numeric Constants 2, 5.6, 9, ► Arithmetic Operations Addition (2+3) Subtraction (2-3) Multiplication (2*3) Division (2/3) Exponentiation (2^3)
Numbers (Contd.) ► Numeric Expressions e.g. (2+3)/5 (5+2) * (2- 10/2) 2.5*2-3^2+14/7
Numbers (Contd.) ► How will this be calculated? 2+10/5 5+2* 2- 1/10 4*6-3^2+5/10 3^2*5
Numbers (Contd.) ► Operator Precedence 1. ^ 2.- operator (indicating a negative value) 3. * and / operator 4. + and - operator
Numbers (Contd.) ► Use parenthesis ( ) to keep intentions clear (2+2)*2? (2+2)*2? 2+2*2? 2+2*2? (5+ (5*2))/(2+1) ? (5+ (5*2))/(2+1) ?
Strings ► E.g: “hello” “9/17/95” “2+3”
What will be printed? ► Picture1.Print 2*3+2 ► Picture1.Print “hello” ► Picture1.Print “2*3+2”
► David Schneider: Chapter 3: Section 3.2 Today’s Lecture was based on ► Scott Warner: Chapter 2: Section 2.1(p48-p50) Chpater5: Section 5.2