Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 Introduction to Computing Dr. Nadeem A Khan

2 Lecture 9

3 Printing strings (Revision) ► 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

4 Printing strings (Revision) ► Displayed result of both print statements same: The balance after a year is 106.55

5 More on Str$ (or Str) and Val ► Dim strVar As String, numVar As Single Let strVar=“68.5” Let strVar=“68.5” Let numVar = Val(strVar) => gets value 68.5 Let numVar = Val(strVar) => gets value 68.5 ► Dim strVar As String Let strVar = Str(60.3) => gets value “ 60.3” Let strVar = Str(60.3) => gets value “ 60.3”

6 The ANSI (ASCII) Character Set ► Characters associated with values 32 (space) 48 0 65 A 176 ° 176 ° 33 ! 49 1 66 B 181 µ 35 # 57 9 97 a 177 ± ► 95 characters => numbers:32 to 126

7 ► Chr$(n) gives character with ANSI value n value n: 32-255 E.g. E.g. ► Chr$(65) =>“A” ► Chr$(32) => “ ” (space) The ANSI Character Set (Contd.)

8 ► Asc(str) gives ANSI value of the first character in the string str E.g. E.g. Asc(“Z”) => 90 Asc(“Z”) => 90 Asc(“z”) => 122 Asc(“z”) => 122 Asc(“Apple”) => 65 Asc(“Apple”) => 65 The ANSI Character Set (Contd.)

9 Let Text1.Text = “32”+Chr$(176)+Chr$(32) +“Fahrenheit” Or Let Text1.Text = “32”+Chr(176)+Chr(32) +“Fahrenheit” What will appear in the Text1 Textbox? The ANSI Character Set (Contd.)

10 The result is: 32° Fahrenheit The ANSI Character Set (Contd.)

11 Sub Text1_KeyPress(KeyAscii as Integer) statements statements End Sub ► Text1_KeyPress event will occur when Text1 has the focus and a key is pressed Text1 has the focus and a key is pressed The Keypress Event Procedure

12 Sub Text1_KeyPress(KeyAscii as Integer) statements statements End Sub ► Keyascii  is a variable (of type Integer)  gets the ANSI value of the pressed key  value is used to display the corresponding character in the Text1 at the end of this procedure The Keypress Event Procedure (Contd.)

13 What will happen in these cases? Sub Text1_KeyPress(KeyAscii as Integer) Let KeyAscii =65 Let KeyAscii =65 End Sub Sub Text1_KeyPress(KeyAscii as Integer) Let KeyAscii =0 Let KeyAscii =0 End Sub The Keypress Event Procedure (Contd.)

14 Assignment 3 ► Assignment 3 has been posted to the CS101 Website. ► The Deadline is on 6:59 p.m. Wednesday Sept. 25.

15 ► David Schneider:  Chapter 3: Section 3.2-3.4 Covered this week ► Scott Warner:  Chapter 2: Section 2.1(p48-p50)  Chapter 4: Section 4.1-4.3  Chpater5: Section 5.2


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

Similar presentations


Ads by Google