330 likes | 460 Views
Introduction to Computing. Dr. Nadeem A Khan. Lecture 11. Data Types !. Data Types. For Strings: Variable-Length String Fixed-Length Strings. Data Types (Contd.). For Numbers (Whole numbers or not): Single (Precision Floating Point) Double (Precision Floating Point) Currency.
E N D
Introduction to Computing Dr. Nadeem A Khan
Data Types • For Strings: • Variable-Length String • Fixed-Length Strings
Data Types (Contd.) • For Numbers (Whole numbers or not): • Single (Precision Floating Point) • Double (Precision Floating Point) • Currency
Data Types (Contd.) • For Numbers (Whole numbers only): • Integer • Long (Integer) • Byte
Data Types (Contd.) • For Boolean values: • Boolean
Variable Names • Use Letters, digits and underscores only • No predefined keywords (integer, single, Dim etc.) • Max. length: 255 chars. (Min. length: 1 char.) • Begin with a letter (e.g. a, A) • Case-Insensitive (Game=GAME=gAme)
Variable Names (Contd.) • Use meaningful names • Good to follow the naming conventions e.g: total numberOfCars
Conversion functions • Already know: • Val • Str$
Conversion functions (Contd.) • Conversion Functions Converts to • Cbool Boolean • Cbyte Byte • Ccur Currency • CDbl Double • Cint Integer • CLng Long • Csng Single • Cstr String
Conversion functions (Contd.) • Converts the input value to a specific data type • Only convert those input values that are appropriate for that data type
More on Print method Using commas: Example • Picture1.Print “North”, “to”, “the”, “future” • Picture1.Print “No:”, 6,
More on Print method (Contd.) Using commas: Result • North to the future • No: 6 (‘6’ displayed 1 pos. further in zone)
More on Print method Using commas: Rules • Line of a Picture Box divided in zones • A Zone: 14 positions • Print Items displayed in consecutive zones
More on Print method Using the Tab function: Example • Picture1.Print “Hello”;Tab(10); “World”; Tab(20);”!” • Picture1.Print “No:”;Tab(5);5
More on Print method (Contd.) Using the Tab function: Result • Hello World ! (‘World’ at 10th position) (‘!’ at 20th position) • No: 5 (‘5’ at 6th position)
More on Print method Using the Tab functions: Rules • Tab(n); (where n is a positive integer) =>Following Item (if possible) displayed beginning at the nth position of the line
More on Print method Using the Spc function: Example • Picture1.Print “Hello”;Spc(3); “World” • Picture1.Print “No:”;Spc(3);5
More on Print method (Contd.) Using the Spc function: Result • Hello World (“World” after 3 spaces) • No: 5 (“5” after 4 spaces)
More on Print method Using the Spc functions: Rules • Spc(n); (where n is a positive integer) =>Following Item printed after n spaces
More on Print method Output to the Printer: • Printer.Print expr =>sends expression expr to the printer =>works the same way as Picture1.Print
More on Print method (Contd.) Output to the Printer: Let Printer.FontName = “Script” Let Printer.FontBold = True Let Printer.FontSize = 12 => set properties
More on Print method (Contd.) Output to the Printer: • Printer.NewPage (new page) • Printer.EndDoc (document ended) • PrintForm (performs the screen dump)
The Message Box for Output • MsgBox message, , “Caption” • A Message Box will appear • displaying the string message • ‘Caption’ will appear in the title bar
The Input Box for Input • Let stringVar = InputBox$(message) • =>An InputBox will appear displaying the string message; Assigns the typed user response to stringVar after Enter is pressed or OK is clicked
Reading Data from File • Open “filespec” For Input As #n • Opens a file for reading and assigns the reference number n • Input #n, var • Next available item is read from the file and assigned to variable var • Close #n • Closes the file
Reading Data from File (Contd.) • DATA.TXT file has two lines: “September” 26 => items separated by commas or line-breaks; data item of same type as the data to be assigned to the corresponding variable
Reading Data from File (Contd.) Example: Sub Command1_Click() Dim month As String, date As Single Picture1.Cls Open “DATA.TXT” For Input As #1 Input #1, month Input #1, date Picture1.Print “ Today is ”; month; date Close #1 End Sub
Reading Data from File (Contd.) The result: Today is September 26
Inclusion of Comments • Rem text • ……………….. ‘text e.g: Rem Compute weekly pay Dim hrs as Single ‘hours worked
Reading for today • Schneider: Section 3.5