egr 141 computer problem solving in engineering and computer science data types and variables
Post on 19-Dec-2015
215 views
TRANSCRIPT
Strings
“(248) 555-1212”“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 StringStringContinuation
Quotes within a string
Strings
lblThetext.Text = “This is the caption for the control “ & _ “called lblThetext!”
String continuation
Strings
Putting the strings together…
lblText.Text = “Hello “ & txtName.Text & “!”
lblText.Text = “Hello txtName.Text !”
lblText2.Text = “Welcome “ & txtName.Text & _ “ to the Grand Hotel.”
Concatenation
CommentsBegin a comment with a ‘ mark
‘This is a commentlblText.Text = “Hello” ‘ Put Hello in the box
Program Header
‘Program: Lab 1 - Hello World‘Form: frmHello‘Programmer: Robin Bank‘Purpose: 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 ("camel-back notation")
– Generally between 5 and 20 characters.
Data Types
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
Data Types
Single. A floating-point (decimal) positive or negative number with a value in the range of up to 3.402823E38 (scientific notation).
Double. A floating-point (decimal) positive or negative number with a value in the range of up to 1.79769313486232E308.
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.
String. Any number of alphabetic, numerical, and special characters.
Date. Dates in the range between January 1, 0001 to December 31, 9999 and times in the range between 0:00:00 to 23:59:59.
Boolean. The value True or False.
Data Types
Data Types
String. Any number of alphabetic, numerical, and special characters.
Date. Dates in the range between January 1, 0001 to December 31, 9999 and times in the range between 0:00:00 to 23:59:59.
Boolean. The value True or False.
Declarations
Dim MyNumber As LongDim MyDecimal As Double
Dim NumberA, NumberB, NumberC As Long
Dim message As StringDim fName, lName As String
Const PI As Double = 3.14159
Declarations
Built-in Constants
System.Drawing.Color.BlackSystem.Drawing.Color.RedSystem.Drawing.Color.LimeSystem.Drawing.Color.YellowSystem.Drawing.Color.BlueSystem.Drawing.Color.MagentaSystem.Drawing.Color.CyanSystem.Drawing.Color.White