1 / 33

Introduction to Computing

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.

odessa
Download Presentation

Introduction to Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computing Dr. Nadeem A Khan

  2. Lecture 11

  3. Data Types !

  4. Data Types • For Strings: • Variable-Length String • Fixed-Length Strings

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

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

  7. Data Types (Contd.) • For Boolean values: • Boolean

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

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

  10. Converting Data Types !

  11. Conversion functions • Already know: • Val • Str$

  12. Conversion functions (Contd.) • Conversion Functions Converts to • Cbool Boolean • Cbyte Byte • Ccur Currency • CDbl Double • Cint Integer • CLng Long • Csng Single • Cstr String

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

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

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

  16. 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

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

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

  19. 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

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

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

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

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

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

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

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

  27. 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

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

  29. 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

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

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

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

  33. Reading for today • Schneider: Section 3.5

More Related