Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computing Dr. Nadeem A Khan. Lecture 7.

Similar presentations


Presentation on theme: "Introduction to Computing Dr. Nadeem A Khan. Lecture 7."— Presentation transcript:

1 Introduction to Computing Dr. Nadeem A Khan

2 Lecture 7

3 Announcement ► New TAs Harris Mukarram Mubashir Amjad Hunain ► Visit the Website for their office hours

4 How to make our user-interface do something?

5 Visual Basic Events ► Event : Action taken by the user e.g.  Clicking a Control  Double Clicking a Control  Getting Focus  Losing Focus etc. etc.

6 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

7 Visual Basic Events (Contd.) ► Names of events => objectName_event ► Events are pre-defined

8 Event Procedure ► Event Procedure: block of code to be executed when an event occurs ► General form Sub objectName_event() statements End Sub

9 Event Procedure (Contd.) ► E.g: Sub Command1_Click() statements End Sub Sub Text1_GotFocus() statements End Sub

10 Statements?

11 VB Statements ► Statements to change the properties of an object the general form: the general form: Let objectName.property = setting

12 Statements (Contd.) Let objectName.property = setting E.g: Let Text1.FontSize = 12 Let Text1.FontBold = TRUE Let Text1.Text = “ ”

13 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

14 Viewing Code Margin Indicator Bar Procedure View Full Module View Object Box Procedures List Box Split Bar

15 Methods ► Another category of statements based on methods

16 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

17 Methods (Contd.) ► General form of these statements => objectName.Method parameters (if any)

18 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

19 Numbers ► Numeric Constants  2, 5.6, 9, 10.005 ► Arithmetic Operations  Addition (2+3)  Subtraction (2-3)  Multiplication (2*3)  Division (2/3)  Exponentiation (2^3)

20 Numbers (Contd.) ► Numeric Expressions e.g.  (2+3)/5  (5+2) * (2- 10/2)  2.5*2-3^2+14/7

21 Numbers (Contd.) ► How will this be calculated?  2+10/5  5+2* 2- 1/10  4*6-3^2+5/10  3^2*5

22 Numbers (Contd.) ► Operator Precedence 1. ^ 2.- operator (indicating a negative value) 3. * and / operator 4. + and - operator

23 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) ?

24 Strings ► E.g:  “hello”  “9/17/95”  “2+3”

25 What will be printed? ► Picture1.Print 2*3+2 ► Picture1.Print “hello” ► Picture1.Print “2*3+2”

26 ► 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


Download ppt "Introduction to Computing Dr. Nadeem A Khan. Lecture 7."

Similar presentations


Ads by Google