Скачать презентацию Introduction to Computing Dr Nadeem A Khan

• Количество слайдов: 33

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

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=g. Ame)

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

Converting Data Types !

Conversion functions ► Already § Val § Str\$ know:

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

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

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

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

More on Print method Using commas: Rules ► Line ►A of a Picture Box divided in zones Zone: 14 positions ► Print Items displayed in consecutive zones

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

More on Print method (Contd. ) Using the Tab function: Result ► Hello World position) ! (‘World’ at 10 th (‘!’ at 20 th position) ► No: 5 (‘ 5’ at 6 th 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 ► Picture 1. Print “Hello”; Spc(3); “World” ► Picture 1. Print “No: ”; Spc(3); 5

More on Print method (Contd. ) Using the Spc function: Result ► Hello ► No: World 5 (“World” after 3 spaces) (“ 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 Picture 1. Print

More on Print method (Contd. ) Output to the Printer: Let Printer. Font. Name = “Script” Let Printer. Font. Bold = True Let Printer. Font. Size = 12 => set properties

More on Print method (Contd. ) Output to the Printer: ► Printer. New. Page (new page) ► Printer. End. Doc (document ended) ► Print. Form (performs the screen dump)

The Message Box for Output ► Msg. Box ► message, , “Caption” A Message Box will appear § displaying the string message § ‘Caption’ will appear in the title bar

The Input Box for Input ► Let ► string. Var = Input. Box\$(message) =>An Input. Box will appear displaying the string message; Assigns the typed user response to string. Var 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 Command 1_Click() Dim month As String, date As Single Picture 1. Cls Open “DATA. TXT” For Input As #1 Input #1, month Input #1, date Picture 1. 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