Introduction to Computing Dr. Nadeem A Khan
Lecture 9
Built-in Functions (Contd.) Fixed length string formatting: Fixed length string formatting: ► FunctionString Value Format$( , Format$(123, Format$(“ ”, Format$(“$1,234.56”, Format$(1/4,
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
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.)
The ANSI (ASCII) Code ► A 7 bit code representing one of the 95 characters (including space) ► Normally one byte is used to store this code
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.)
Generating Random Numbers The function: Rnd The function: Rnd ► Generates a random number from 0 up to but not including 1 Picture1.Print Rnd‘print a different number each time Let numvar= Rnd‘a random value is assigned
Generating Random Numbers (Contd.) The function: Rnd The function: Rnd Display numbers from the set {1,2,3,4,5,6} randomly!
Generating Random Numbers (Contd.) The statement: Randomize Timer? The statement: Randomize Timer?
Generating Random Numbers (Contd.) The statement: Randomize Timer The statement: Randomize Timer Sub Command1_Click ( ) Rem Display a lottery number Picture1.Cls Randomize Timer Picture1.Print Int(10*Rnd); Picture1.Print Int(10*Rnd) End Sub
Read Chapter 4 completely