Microsoft Visual Basic 2005 BASICS Lesson 5 Data Types and Variables
Objectives <ul><li>Describe the purpose of data types and variables. </li></ul><ul><li>Use the AutoSize property. </li></u...
Data Types <ul><li>Computers are all about data. </li></ul><ul><li>Visual Basic supports a certain set of data types. </li...
Data Types (cont.)
Using the AutoSize Property <ul><li>The AutoSize property </li></ul><ul><ul><li>Adjusts the size of a control to fit its c...
Using the AutoSize Property (cont.)
Using the AutoSize Property (cont.)
Declaring Variables <ul><li>Using a variable in your programs </li></ul><ul><ul><li>Let the compiler know  </li></ul></ul>...
Rules for Naming Variables <ul><li>When naming variables, keep the following rules in mind: </li></ul><ul><ul><li>Variable...
Rules for Naming Variables (cont.)
Using Variables <ul><li>Variables can be used in the same way as labels and text boxes. </li></ul><ul><li>Use the assignme...
Using Variables (cont.) <ul><li>Use mathematical operators to perform calculations with numeric variables. </li></ul><ul><...
Using Variables (cont.)
Using Variables (cont.)
Scope <ul><li>The term “scope” refers to the reach of a variable. </li></ul><ul><li>General rule </li></ul><ul><ul><li>You...
Three Levels of Scope <ul><li>Levels </li></ul><ul><ul><li>Local variable </li></ul></ul><ul><ul><ul><li>Declared within a...
The Declarations Section <ul><li>Access the Declarations section </li></ul><ul><ul><li>Select (Declarations) from the Meth...
The Declarations Section (cont.)
The Declarations Section (cont.)
Using the Object Data Type <ul><li>Object data type </li></ul><ul><ul><li>Very flexible </li></ul></ul><ul><ul><li>Can sto...
Summary <ul><li>Data can be in the form of numbers, text, dates, pictures, and even sound. </li></ul><ul><li>Visual Basic ...
Summary (cont.) <ul><li>The AutoSize property will adjust the size of a control to fit its contents. </li></ul><ul><li>The...
Summary (cont.) <ul><li>You can assign values to variables using the assignment operator. </li></ul><ul><ul><li>You can al...
Summary (cont.) <ul><li>The Declarations section of a form’s Code window allows you to declare form-level variables. </li>...
Upcoming SlideShare
Loading in …5
×

Lesson 5 PP

672 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
672
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lesson 5 PP

  1. 1. Microsoft Visual Basic 2005 BASICS Lesson 5 Data Types and Variables
  2. 2. Objectives <ul><li>Describe the purpose of data types and variables. </li></ul><ul><li>Use the AutoSize property. </li></ul><ul><li>Declare and use variables. </li></ul><ul><li>Describe the scope of variables. </li></ul><ul><li>Describe the Object data type. </li></ul>
  3. 3. Data Types <ul><li>Computers are all about data. </li></ul><ul><li>Visual Basic supports a certain set of data types. </li></ul><ul><li>You can choose to store data in memory locations called variables. </li></ul><ul><li>Variables </li></ul><ul><ul><li>Can be used to store and manipulate all kinds of data </li></ul></ul>
  4. 4. Data Types (cont.)
  5. 5. Using the AutoSize Property <ul><li>The AutoSize property </li></ul><ul><ul><li>Adjusts the size of a control to fit its contents </li></ul></ul><ul><li>Label control example </li></ul><ul><ul><li>The AutoSize property will shrink or enlarge the label to fit the text. </li></ul></ul>
  6. 6. Using the AutoSize Property (cont.)
  7. 7. Using the AutoSize Property (cont.)
  8. 8. Declaring Variables <ul><li>Using a variable in your programs </li></ul><ul><ul><li>Let the compiler know </li></ul></ul><ul><ul><ul><li>That you want to set up a memory location as a variable </li></ul></ul></ul><ul><ul><ul><li>What you want to call the variable </li></ul></ul></ul><ul><ul><ul><li>What data type you want the variable to have </li></ul></ul></ul><ul><li>Declare a variable </li></ul><ul><ul><li>Use the Dim statement </li></ul></ul>
  9. 9. Rules for Naming Variables <ul><li>When naming variables, keep the following rules in mind: </li></ul><ul><ul><li>Variable names must begin with an alphabetic character. </li></ul></ul><ul><ul><li>Following the first character, letters, numbers, and underscores are allowed. </li></ul></ul><ul><ul><li>Variable names cannot include spaces. </li></ul></ul><ul><ul><li>Variable names can be 255 characters long. </li></ul></ul>
  10. 10. Rules for Naming Variables (cont.)
  11. 11. Using Variables <ul><li>Variables can be used in the same way as labels and text boxes. </li></ul><ul><li>Use the assignment operator to assign a value to a variable. </li></ul><ul><ul><li>You can also assign hard-coded values to a variable. </li></ul></ul>
  12. 12. Using Variables (cont.) <ul><li>Use mathematical operators to perform calculations with numeric variables. </li></ul><ul><li>Output the value in a variable. </li></ul><ul><ul><li>Assign the value to a label. </li></ul></ul>
  13. 13. Using Variables (cont.)
  14. 14. Using Variables (cont.)
  15. 15. Scope <ul><li>The term “scope” refers to the reach of a variable. </li></ul><ul><li>General rule </li></ul><ul><ul><li>You should declare variables as locally as possible. </li></ul></ul>
  16. 16. Three Levels of Scope <ul><li>Levels </li></ul><ul><ul><li>Local variable </li></ul></ul><ul><ul><ul><li>Declared within an event procedure </li></ul></ul></ul><ul><ul><li>Form-level variable </li></ul></ul><ul><ul><ul><li>Declared in the Declarations section of a form’s Code window </li></ul></ul></ul><ul><ul><li>Global variable </li></ul></ul><ul><ul><ul><li>Declared in a code module’s section </li></ul></ul></ul>
  17. 17. The Declarations Section <ul><li>Access the Declarations section </li></ul><ul><ul><li>Select (Declarations) from the Method Name list that appears at the top of the Code window. </li></ul></ul>
  18. 18. The Declarations Section (cont.)
  19. 19. The Declarations Section (cont.)
  20. 20. Using the Object Data Type <ul><li>Object data type </li></ul><ul><ul><li>Very flexible </li></ul></ul><ul><ul><li>Can store many different types of variables </li></ul></ul><ul><li>Object variables </li></ul><ul><ul><li>Can be declared by specifying the Object type </li></ul></ul><ul><ul><li>Or by declaring a variable without a type </li></ul></ul>
  21. 21. Summary <ul><li>Data can be in the form of numbers, text, dates, pictures, and even sound. </li></ul><ul><li>Visual Basic supports a set of data types. There are data types for whole numbers, floating-point numbers (decimals), text, dates, and more. </li></ul><ul><li>You can choose to store data in memory locations called variables. </li></ul>
  22. 22. Summary (cont.) <ul><li>The AutoSize property will adjust the size of a control to fit its contents. </li></ul><ul><li>The first step to using a variable is to declare it using the Dim statement. </li></ul><ul><li>When naming variables, keep the naming rules in mind. It is a good idea to use naming prefixes to identify the data type of the variable. </li></ul>
  23. 23. Summary (cont.) <ul><li>You can assign values to variables using the assignment operator. </li></ul><ul><ul><li>You can also use the other mathematical operators with numeric variables. </li></ul></ul><ul><li>A variable’s scope indicates the procedures that have access to the variable. A variable’s scope can be local, form-level, or global. </li></ul>
  24. 24. Summary (cont.) <ul><li>The Declarations section of a form’s Code window allows you to declare form-level variables. </li></ul><ul><li>The Object data type can hold many different kinds of data, but is less efficient than specific data types. </li></ul>

×