Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 Introduction to Computing Dr. Nadeem A Khan

2 Lecture 11

3 Data Types !

4 ► For Strings:  Variable-Length String  Fixed-Length Strings Data Types

5 ► For Numbers (Whole numbers or not):  Single (Precision Floating Point)  Double (Precision Floating Point)  Currency Data Types (Contd.)

6 ► For Numbers (Whole numbers only):  Integer  Long (Integer)  Byte Data Types (Contd.)

7 ► For Boolean values:  Boolean Data Types (Contd.)

8 ► 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

9 ► Use meaningful names ► Good to follow the naming conventions e.g: e.g: total total numberOfCars numberOfCars Variable Names (Contd.)

10 Converting Data Types !

11 ► Already know:  Val  Str$ Conversion functions

12 ► Conversion FunctionsConverts to  CboolBoolean  CbyteByte  CcurCurrency  CDblDouble  CintInteger  CLngLong  CsngSingle  CstrString Conversion functions (Contd.)

13 ► Converts the input value to a specific data type ► Only convert those input values that are appropriate for that data type for that data type Conversion functions (Contd.)

14 Using commas: Example Using commas: Example ► Picture1.Print “North”, “to”, “the”, “future” ► Picture1.Print “No:”, 6, More on Print method

15 Using commas: Result Using commas: Result ► North to the future ► No: 6 (‘6’ displayed 1 pos. further in zone) More on Print method (Contd.)

16 Using commas: Rules 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

17 Using the Tab function: Example Using the Tab function: Example ► Picture1.Print “Hello”;Tab(10); “World”; Tab(20);”!” ► Picture1.Print “No:”;Tab(5);5 More on Print method

18 Using the Tab function: Result Using the Tab function: Result ► HelloWorld!(‘World’ at 10th position) (‘!’ at 20th position) (‘!’ at 20th position) ► No: 5 (‘5’ at 6th position) More on Print method (Contd.)

19 Using the Tab functions: Rules 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 =>Following Item (if possible) displayed beginning at the nth position of the line More on Print method

20 Using the Spc function: Example Using the Spc function: Example ► Picture1.Print “Hello”;Spc(3); “World” ► Picture1.Print “No:”;Spc(3);5 More on Print method

21 Using the Spc function: Result Using the Spc function: Result ► Hello World(“World” after 3 spaces) ► No: 5 (“5” after 4 spaces) More on Print method (Contd.)

22 Using the Spc functions: Rules Using the Spc functions: Rules ► Spc(n); (where n is a positive integer) =>Following Item printed after n spaces =>Following Item printed after n spaces More on Print method

23 Output to the Printer: Output to the Printer: ► Printer.Print expr =>sends expression expr to the printer =>works the same way as Picture1.Print More on Print method

24 Output to the Printer: Output to the Printer: Let Printer.FontName = “Script” Let Printer.FontBold = True Let Printer.FontSize = 12 => set properties More on Print method (Contd.)

25 Output to the Printer: Output to the Printer: ► Printer.NewPage (new page) ► Printer.EndDoc (document ended) ► PrintForm (performs the screen dump) More on Print method (Contd.)

26 ► MsgBox message,, “Caption” ► A Message Box will appear  displaying the string message  ‘Caption’ will appear in the title bar The Message Box for Output

27 ► 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 The Input Box for Input

28 ► 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

29 ► 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 data item of same type as the data to be assigned to the corresponding variable assigned to the corresponding variable Reading Data from File (Contd.)

30 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.)

31 The result: Today is September 26 Reading Data from File (Contd.)

32 ► Rem text ► ……………….. ‘text e.g: Rem Compute weekly pay Dim hrs as Single ‘hours worked Inclusion of Comments

33 Reading for today ► Schneider: Section 3.5


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

Similar presentations


Ads by Google