EGR 141 Computer Problem Solving in Engineering and
EGR 141 Computer Problem Solving in Engineering and Computer Science Data Types and Variables
Strings “(248) 555 -1212” Quotes within a string “Hello, this is a string!” “The article ””Small Miracles”” is good” “This is an example of a string in Visual Basic “ & _ “that goes for more than one line. It can even “ & _ “go on for three lines. ” “” Empty String Continuation
Strings lbl. Thetext. Text = “This is the caption for the control “ & _ “called lbl. Thetext!” String continuation
Strings Putting the strings together… lbl. Text = “Hello “ & txt. Name. Text & “!” lbl. Text = “Hello txt. Name. Text !” lbl. Text 2. Text = “Welcome “ & txt. Name. Text & _ “ to the Grand Hotel. ” Concatenation
Comments Begin a comment with a ‘ mark ‘This is a comment lbl. Text = “Hello” ‘ Put Hello in the box Program Header ‘Program: ‘Form: ‘Programmer: ‘Purpose: ‘ ‘ Lab 1 - Hello World frm. Hello Robin Bank The user can enter their name and when they click the ‘Show Message’ button it will welcome them.
Variable Names • VB Rules – <= 255 characters – must begin with an alphabetic character – can't contain punctuation characters (except underscore "_") – must be unique within the same scope – case insensitive – can't be the same as a keyword • Textbook Conventions – be meaningful and descriptive – use consistent abbreviations for same word – use entire words or initial syllables – use mixed case, with a capital letter at the start of each word ("camelback notation") – Generally between 5 and 20 characters.
Data Types ·Short. A non-decimal (whole) number with a value in the range of -32, 768 to +32, 767. ·Integer. A non-decimal (whole) number with a value in the range of -2, 147, 483, 648 to +2, 147, 483, 647. ·Long. A non-decimal (whole) number with a value in the range of -9, 223, 372, 036, 854, 775, 808 to +9, 223, 372, 036, 854, 775, 807.
Data Types ·Single. A floating-point (decimal) positive or negative number with a value in the range of up to 3. 402823 E 38 (scientific notation). ·Double. A floating-point (decimal) positive or negative number with a value in the range of up to 1. 79769313486232 E 308. ·Decimal. A decimal number with a value in the range of up to +79, 228, 162, 514, 264, 337, 593, 950, 335. without decimal precision and up to +7. 9228162514264337593543950335 with 28 places of decimal precision.
Data Types ·String. Any number of alphabetic, numerical, and special characters. ·Dates in the range between January 1, 0001 to December 31, 9999 and times in the range between 0: 00 to 23: 59. ·Boolean. The value True or False.
Declarations Dim My. Number As Long Dim My. Decimal As Double Dim Number. A, Number. B, Number. C As Long Dim message As String Dim f. Name, l. Name As String Const PI As Double = 3. 14159
Declarations Built-in Constants System. Drawing. Color. Black System. Drawing. Color. Red System. Drawing. Color. Lime System. Drawing. Color. Yellow System. Drawing. Color. Blue System. Drawing. Color. Magenta System. Drawing. Color. Cyan System. Drawing. Color. White
Usage Form 1. Active. Form. Back. Color = System. Drawing. Color. Red _________________________ Me. Back. Color = System. Drawing. Color. Red _________________________ Refers to the current, active form
- Slides: 12