24
Microsoft Visual Basic 2005 BASICS Lesson 7 Strings and Decimal Types

Ppt lesson 07

Embed Size (px)

Citation preview

Page 1: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS

Lesson 7

Strings and Decimal Types

Page 2: Ppt lesson 07

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.

Page 3: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 3

Objectives (cont.)

Use the Enabled property. Use the SelectionStart and

SelectionLength properties.

Page 4: Ppt lesson 07

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.

Page 5: Ppt lesson 07

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.

Page 6: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 6

Assigning Text to String Variables (cont.)

Page 7: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 7

Assigning Text to String Variables (cont.)

Page 8: Ppt lesson 07

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.

Page 9: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 9

Concatenation (cont.)

Page 10: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 10

Concatenation (cont.)

Page 11: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 11

Concatenation (cont.)

Page 12: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 12

Concatenation (cont.)

Page 13: Ppt lesson 07

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

Page 14: Ppt lesson 07

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.

Page 15: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 15

Using the Format Function (cont.)

Page 16: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 16

Using the Format Function (cont.)

Page 17: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 17

Using the Format Function (cont.)

Page 18: Ppt lesson 07

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.

Page 19: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 19

Using the Enabled Property (cont.)

To disable an object, set the Enabled property to False.

Page 20: Ppt lesson 07

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

Page 21: Ppt lesson 07

Microsoft Visual Basic 2005 BASICS 21

Using the SelectionStart and SelectionLength Properties (cont.)

Page 22: Ppt lesson 07

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.

Page 23: Ppt lesson 07

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.

Page 24: Ppt lesson 07

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.