Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 Introduction to Computing Dr. Nadeem A Khan

2 Lecture 8

3 Scientific Notation ► E=Exponent => Exponent of 10 E.g.  1.2E+04 = 1.2 * 10^4 = 12000  1.2E+34 = 1.2 * 10^34  1E-02 = 1 * 10^-2 =.01

4 Scientific Notation (Contd.) ► Display notation (Scientific or Standard) depends on magnitude

5 ► What this code will do? Let num1 = 6 Picture1.Print num1 Picture1.Print num1

6 Variables (Contd.) Conclusions: ► A variable holds a value ► The value can be assigned and then used

7 Variables (Contd.) ► What will this code do? Let result = 100*4 Picture1.Print result Picture1.Print result

8 Variables (Contd.) ► What will this code do? Let speed=50.3 Let speed=50.3 Let timeElapsed =2 Let timeElapsed =2 Let distance = speed*timeElapsed Picture1.Print distance Picture1.Print distance

9 Variables (Contd.) ► Conclusions: The General Form: Let var = expression e.g.:Distance=speed*timeElapsed c= a*(2.2+b)+6 counter=counter+1

10 String Variables Sub Command1_Click () Picture1.Cls Picture1.Print “hello” Let today = “9/17/95” Let message = “students of CS101” Picture1.Print today Picture1.Print “hello”; message End Sub

11 String Variables (Contd.) ► Result: hello9/17/95 hellostudents of CS101

12 String Variables (Contd.) ► Concatenation (use + or &) Sub Command1_Click () Picture1.Cls Let message_part1 = “hello” Let message_part2 = “students of CS101” Let message= message_part1+message_part2 Picture1.Print message Picture1.Print message + “ on Sept. 19,2002” Let message= message_part1 & “ world” Picture1.Print message End Sub

13 String Variables (Contd.) ► Displayed Result hellostudents of CS101 hellostudents of CS101 on Sept. 19,2002 hello world

14 Declaring Variable Types ► Dim var As String ► Dim var As Single

15 Declaring Variable Types (Contd.) ► Example program: Sub Command1_Click () Dim interestRate As Single Dim principal As Single Dim phrase as String Picture1.Cls Let InterestRate=.0655 Let principal =100 Let phrase =“The balance after a year is” Picture1.Print phrase;(1+interestRate)*principal End Sub

16 Declaring Variable Types (Contd.) ► Displayed Result: The balance after a year is 106.55

17 Declaring Variable Types (Contd.) ► Different ways of declaration  Dim interestRate As Single, principal As Single, phrase As String  Dim name$ (same as Dim name As String)  Dim price! (same as Dim price As Single)  Use the type declaration tag while using it E.g.: Let name$ = “John” Let price! = 65.66

18 Input/Output Using Text Box ► Contents of a text box is always a string ► Output the string by  Let Text1.Text= strvar ► Input the string by  Let strVar =Text1.Text

19 Input/Output Using Text Box (Contd.) ► Numbers in a textbox are also stored as strings ► Input a number by  Let numVar = Val(Text1.Text) ► Output a number by  Let Text1.Text=Str$(numVar)

20 Another example: Sub Command1_Click() Picture1.Cls Let rate = 50 Let timeElapsed = 14 Let distance = rate * timeElapsed Picture1.Print distance Let distance = 410 Let timeElaspsed = distance / rate Picture1.Print timeElapsed End Sub


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

Similar presentations


Ads by Google