1 / 20

# Data Types and Variables Lesson 6! - PowerPoint PPT Presentation

Data Types and Variables Lesson 6!. Data Type!. Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures. Visual Basic supports the following data types: Data Type Range Whole Number: Integer -32,768 to 32,767 Long -2,147,483,648 to 2,147,483,647

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' Data Types and Variables Lesson 6!' - pelagia-aradia

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Data Types and VariablesLesson 6!

Data can be in the form of

• Text

• Dates

• Sounds

• Pictures

Data TypeRange

Whole Number:

Integer -32,768 to 32,767

Long -2,147,483,648 to

2,147,483,647

Decimal Number:

Single -3,402823E+38 to

3,402823E+38

Double -1,79769313486232E+308

to 1,79769313486232E+308

Data TypeRange

Other Types:

characters

Date January 1, 100 to

December 31, 9999

Boolean True or False

Definition:

Memory locations where temporary data is stored.

• Variables are a common feature of programming languages.

• Variables can be used to store and manipulate all kinds of data.

• Variables get their name from the fact that the value can vary as the program runs.

• You can assign values to variables using the assignment operator. (=)

• You should declare variables before you use them.

• The first step to using a variable in your program is to:

• Let the compiler know that you want to set up a memory location as a variable.

• What you want to call the variable.

• What data type you want the variable to have.

• The above process is called declaring a variable!

To declare a variable, use the Dim statement as show below.

Dim VariableName As DataType

The following declare a variable named intAnswer with the Integer data type.

When naming variables, keep the following rules in mind.

• Variable names must begin with an alphabetic character ( a letter).

• Following the first character, letters, numbers, and the underscore (_) are allowed.

• Variable names cannot include any spaces.

• Variable names can be up to 255 character long.

PrefixData TypeExample

int Integer intPeople

lng Long lngInches

sng Single sngWeight

dbl Double dblMass

str String strName

dte Date dteAnniversary

bln Boolean blnSold

Open VB and create a new form the looks like the following:

• Set the name properties to the following:

Label1 should be lblAgeYears

Label2 should be lblMonths

Label3 should be lblYou

Label4 should be lblOutputMonths

Label5 should be lblAgeMonths

• Add two text boxes to your form. caption to Month Converter.

• Set the name of the text boxes to

txtYears

txtMonths

• Set the name of the command button to cmdMonths

• Set the caption to Calculate age in months

• Change the properties of the following labels to caption to Month Converter.false.

lblYou, lblOutputMonths, lblAgemonths

• Double-click the Calculate age in months button.

• Key Dim intMonths As Integer at the top of the event procedure and press the Enter key twice.

• Enter the following: caption to Month Converter.

'Calculate Months

intMonths = (Val(txtYears.Text) * 12) + _

Val(txtMonths.Text)

'Display Number of Months Old

lblOutputMonths.Caption = intMonths

lblYou.Visible = True

lblOutputMonths.Visible = True

lblAgemonths.Visible = True

• Run and fix your errors. caption to Month Converter.

• Enter 5 in the Age in years text box.

• Enter 4 in the Months since last birthday text box.

• Click the Calculate age in months button.

Summary caption to Month Converter.

• Data can be in the form of numbers, text, dates, pictures, and even sound.

• Visual Basic supports a set of data types.

• There are data types for whole numbers, floating point numbers (decimals), text, dates, and more.

• You can choose to store data in memory locations called variables.

Summary caption to Month Converter.

• The first step to using a variable is to declare it using the Dim statement.

• When naming variables, keep the naming rules in mind. It is also a good idea to use naming prefixes to identify the data type of the variable.

• You should declare variables before you use them.

• You can assign values to variables using the assignment operator (=).

Homework: caption to Month Converter.

Pick up a worksheet before

you leave!