ppt lesson 07
TRANSCRIPT
Microsoft Visual Basic 2005 BASICS
Lesson 7
Strings and Decimal Types
Microsoft Visual Basic 2005 BASICS 2
Objectives
Declare string variables. Assign text to string variables. Concatenate strings. Use decimal data types. Use the Format function.
Microsoft Visual Basic 2005 BASICS 3
Objectives (cont.)
Use the Enabled property. Use the SelectionStart and
SelectionLength properties.
Microsoft Visual Basic 2005 BASICS 4
Declaring String Variables
Text is often called alphanumeric data. Can include letters or numbers
Data types that hold text are usually referred to as strings.
When you declare a string, the resulting variable can hold a string of any practical length.
Microsoft Visual Basic 2005 BASICS 5
Assigning Text to String Variables
Place the text in quotation marks. Hard-coded text is called a string literal. Like a numeric variable, a string variable
can only hold one string. Each time you assign a string to a string
variable, the existing data is replaced.
Microsoft Visual Basic 2005 BASICS 6
Assigning Text to String Variables (cont.)
Microsoft Visual Basic 2005 BASICS 7
Assigning Text to String Variables (cont.)
Microsoft Visual Basic 2005 BASICS 8
Concatenation
Concatenation Appends one string to the end of another
Ampersand (&) You can concatenate more than two
strings in one expression. You can also use concatenation when
creating the text for a label.
Microsoft Visual Basic 2005 BASICS 9
Concatenation (cont.)
Microsoft Visual Basic 2005 BASICS 10
Concatenation (cont.)
Microsoft Visual Basic 2005 BASICS 11
Concatenation (cont.)
Microsoft Visual Basic 2005 BASICS 12
Concatenation (cont.)
Microsoft Visual Basic 2005 BASICS 13
Using Decimal Types
Single data type Used for decimal values that will not
exceed 38 digits Double data type
Used for decimal values with more than 38 digits
Decimal data type Used to work with dollars and cents
Microsoft Visual Basic 2005 BASICS 14
Using the Format Function
The Format function Allows you to apply custom formatting to a
number before displaying the value The Format function can be used to
format decimal values, phone numbers, and more.
Microsoft Visual Basic 2005 BASICS 15
Using the Format Function (cont.)
Microsoft Visual Basic 2005 BASICS 16
Using the Format Function (cont.)
Microsoft Visual Basic 2005 BASICS 17
Using the Format Function (cont.)
Microsoft Visual Basic 2005 BASICS 18
Using the Enabled Property
Enabled property Makes a control take on a grayed
appearance that makes it inactive but still visible
Objects that are inactive can be seen by the user, but will not respond to user actions.
Microsoft Visual Basic 2005 BASICS 19
Using the Enabled Property (cont.)
To disable an object, set the Enabled property to False.
Microsoft Visual Basic 2005 BASICS 20
Using the SelectionStart and SelectionLength Properties
SelectionStart property Specifies the location where the insertion
point will be inserted when the text box gets the focus
SelectionLength property Specifies how many characters should be
selected to the right of the cursor
Microsoft Visual Basic 2005 BASICS 21
Using the SelectionStart and SelectionLength Properties (cont.)
Microsoft Visual Basic 2005 BASICS 22
Summary
Strings hold text or alphanumeric data. Visual Basic has a data type for strings. Text assigned to a string variable must
be placed in quotation marks. You can use the assignment operator to
assign text from a text box to a string variable or from a string variable to another string variable.
Microsoft Visual Basic 2005 BASICS 23
Summary (cont.)
Concatenation is the process of appending one string to the end of another.
The ampersand (&) is the symbol used for concatenation.
The Single, Double, and Decimal data types hold decimal data.
The Decimal data type is specially designed for handling dollars and cents.
Microsoft Visual Basic 2005 BASICS 24
Summary (cont.)
The Format function uses a string of symbols to format decimal values, phone numbers, and more.
The Enabled property is used to make a control inactive or active.
The SelectionStart and SelectionLength properties and the Len function can be used together to highlight the text in a text box.