introduction to computing dr. nadeem a khan. lecture 7

26
Introduction to Introduction to Computing Computing Dr. Nadeem A Khan Dr. Nadeem A Khan

Post on 20-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Introduction to Introduction to ComputingComputing

Dr. Nadeem A KhanDr. Nadeem A Khan

Lecture 7Lecture 7

AnnouncementAnnouncement

► New TAs New TAs

Harris MukarramHarris Mukarram

Mubashir Amjad Hunain Mubashir Amjad Hunain

► Visit the Website for their office Visit the Website for their office hourshours

How to make our user-How to make our user-interface do something?interface do something?

Visual Basic EventsVisual Basic Events

► EventEvent : Action taken by the user e.g.: Action taken by the user e.g.

Clicking a ControlClicking a Control

Double Clicking a ControlDouble Clicking a Control

Getting FocusGetting Focus

Losing Focus Losing Focus

etc. etc.etc. etc.

Visual Basic Events Visual Basic Events (Contd.)(Contd.)► Naming of EventsNaming of Events

Clicking a Command Button 1Clicking a Command Button 1►Command1_ClickCommand1_Click

Double Clicking a Picture Box 2Double Clicking a Picture Box 2►Picture2_DblClickPicture2_DblClick

Text box 1 gets FocusText box 1 gets Focus►Text1_GotFocusText1_GotFocus

Text box 1 loses Focus Text box 1 loses Focus ►Text1_LostFocusText1_LostFocus

Visual Basic Events Visual Basic Events (Contd.)(Contd.)

►Names of eventsNames of events

=> => objectName_eventobjectName_event

►Events are pre-definedEvents are pre-defined

Event ProcedureEvent Procedure

►Event ProcedureEvent Procedure: : block of code to be block of code to be executed when an event occursexecuted when an event occurs

►General formGeneral formSub Sub objectName_event()objectName_event()

statementsstatements

End SubEnd Sub

Event Procedure Event Procedure (Contd.)(Contd.)

►E.g:E.g:Sub Command1_Click()Sub Command1_Click()

statementsstatements

End SubEnd Sub

Sub Text1_GotFocus()Sub Text1_GotFocus()

statementsstatements

End SubEnd Sub

Statements?Statements?

VB StatementsVB Statements

►Statements to change the Statements to change the propertiesproperties of an object of an object

the general form:the general form:LetLet objectName.property = setting objectName.property = setting

Statements Statements (Contd.)(Contd.)

LetLet objectName.property = setting objectName.property = setting

E.g:E.g:

Let Text1.FontSize = 12Let Text1.FontSize = 12

Let Text1.FontBold = TRUELet Text1.FontBold = TRUE

Let Text1.Text = “ ”Let Text1.Text = “ ”

Event Procedure Event Procedure (Contd.)(Contd.)

► Event procedureEvent procedure – general form – general formSub Sub objectName_eventobjectName_event()()

statementsstatementsEnd SubEnd Sub

► ExampleExampleSub Command1_Click()Sub Command1_Click()

Let Text1.text = “”Let Text1.text = “”Let Text2.text=“Hello”Let Text2.text=“Hello”

End SubEnd Sub

Viewing CodeViewing Code

Margin Indicato

r Bar

Procedure View

Full Module View

Object Box

Procedures List Box

Split Bar

MethodsMethods

►Another category of Another category of statements based on methods statements based on methods

Methods Methods (Contd.)(Contd.)

►E.g:E.g:

Picture1.ClsPicture1.Cls

Clears Picture1 Picture BoxClears Picture1 Picture Box

Picture1.Print 3 Picture1.Print 3

Prints ‘3’Prints ‘3’ in the Picture1 Picture Boxin the Picture1 Picture Box

Methods Methods (Contd.)(Contd.)

►General form of these statementsGeneral form of these statements

=> => objectName.Method objectName.Method parametersparameters

(if any)(if any)

TheThe Print Method Print Method

► Picture1.Print Picture1.Print mm ??

► Picture1.Print Picture1.Print mm;; ??

► Picture1.Print Picture1.Print mm; ; nn; ; r r ??

m, n, rm, n, r are numbers e.g. 3, 5.2 are numbers e.g. 3, 5.2

NumbersNumbers

►Numeric Constants Numeric Constants 2, 5.6, 9, 10.0052, 5.6, 9, 10.005

►Arithmetic OperationsArithmetic Operations Addition (2+3)Addition (2+3) Subtraction (2-3)Subtraction (2-3) Multiplication (2*3)Multiplication (2*3) Division (2/3)Division (2/3) Exponentiation (2^3)Exponentiation (2^3)

Numbers Numbers (Contd.)(Contd.)

►Numeric Expressions Numeric Expressions e.g.e.g.

(2+3)/5(2+3)/5

(5+2) * (2- 10/2)(5+2) * (2- 10/2)

2.5*2-3^2+14/72.5*2-3^2+14/7

Numbers Numbers (Contd.)(Contd.)

► How will this be calculated?How will this be calculated?

2+10/52+10/5

5+2* 2- 1/105+2* 2- 1/10

4*6-3^2+5/104*6-3^2+5/10

3^2*53^2*5

Numbers Numbers (Contd.)(Contd.)

►Operator PrecedenceOperator Precedence

1. ^1. ^

2.- operator (indicating a negative 2.- operator (indicating a negative value)value)

3. * and / operator3. * and / operator

4. + and - operator4. + and - operator

Numbers Numbers (Contd.)(Contd.)

►Use parenthesis ( ) to keep intentions Use parenthesis ( ) to keep intentions clearclear

(2+2)*2(2+2)*2 ??

2+2*22+2*2 ??

(5+ (5*2))/(2+1) ?(5+ (5*2))/(2+1) ?

Strings Strings

►E.g:E.g:

““hello”hello”

““9/17/95”9/17/95”

““2+3”2+3”

What will be printed?What will be printed?

► Picture1.Print 2*3+2Picture1.Print 2*3+2

► Picture1.Print “hello”Picture1.Print “hello”

► Picture1.Print “2*3+2”Picture1.Print “2*3+2”

►David Schneider:David Schneider: Chapter 3: Section 3.2Chapter 3: Section 3.2

Today’s Lecture was based Today’s Lecture was based on on

►Scott Warner:Scott Warner: Chapter 2: Section 2.1(p48-p50)Chapter 2: Section 2.1(p48-p50) Chpater5: Section 5.2Chpater5: Section 5.2