Presentation is loading. Please wait.

Presentation is loading. Please wait.

VARIABLES: Your Own Piece of the ram. Why Use Variables? To save a piece of data in memory To save a piece of data in memory To store results of a calculation.

Similar presentations


Presentation on theme: "VARIABLES: Your Own Piece of the ram. Why Use Variables? To save a piece of data in memory To save a piece of data in memory To store results of a calculation."— Presentation transcript:

1 VARIABLES: Your Own Piece of the ram

2 Why Use Variables? To save a piece of data in memory To save a piece of data in memory To store results of a calculation To store results of a calculation To make code easier to modify/understand To make code easier to modify/understand

3 A variable is a named memory location that stores a value.

4 Variables must be declared before they can be used! DimIntlength As Integer Intlength - variable name Integer - data type Dim - stands for dimension As – reserved word

5 Variable Naming Rules Must begin with a letter. Must begin with a letter. Must only contain letters, digits, and underscores (_). Must only contain letters, digits, and underscores (_). Must not be a keyword (i.e. End, Sub, If). Must not be a keyword (i.e. End, Sub, If). Use the proper abbreviation Use the proper abbreviation (on the naming convention slide). (on the naming convention slide).

6 Naming Conventions Shortsrt Integerint Longlng Decimaldec Single sng Doubledbl Stringstr Charchr Datedte Booleanbln

7 Variable Data Types Numbers ( Whole Numbers or Decimals) Numbers ( Whole Numbers or Decimals) Whole Numbers Short, Integer, Long Decimal Single, Double,Decimal Text (String or Char) Text (String or Char) Dates (Date) Dates (Date) State (True or False: Boolean) State (True or False: Boolean)

8 How Do You Choose What Data Type to Use? Short -32,768 to 32,767 Integer-2,147,483,648 to 2,147,483,647 Longlarge integers Singlenumbers containing a decimal Doublelarge decimal numbers Date dates in m/d/yyyy format Decimalnumbers used for currency Chara single character Stringa set of characters in “ ” BooleanTrue or False

9 What Data Type Do You Use? 1. Number of students in class 2. Class average Choices 3. Name of the School 4. Grade Given as a Letter

10 What Kind of Variable Do You Use? 5. Distance to the Moon 6. Has the Bill Been Paid? Choices 7. Cost of a pizza 8. Date of the Last Day of School

11 Declaration Statements 1. Number of students in class 2. Class average 3. Name of the School 4. Grade Given as a Letter 5. Distance to the Moon 6. Has the Bill Been Paid? 7. Cost of a pizza 8. Date of the Last Day of School Dim srtstudent as short Dim srtstudent as short _______________________________ _________________________


Download ppt "VARIABLES: Your Own Piece of the ram. Why Use Variables? To save a piece of data in memory To save a piece of data in memory To store results of a calculation."

Similar presentations


Ads by Google