SlideShare a Scribd company logo
Microsoft Visual Basic 2005 BASICS Lesson 5 Data Types and Variables
Objectives Describe the purpose of data types and variables. Use the AutoSize property. Declare and use variables. Describe the scope of variables. Describe the Object data type.
Data Types Computers are all about data. Visual Basic supports a certain set of data types. You can choose to store data in memory locations called variables. Variables Can be used to store and manipulate all kinds of data
Data Types (cont.)
Using the AutoSize Property The AutoSize property Adjusts the size of a control to fit its contents Label control example The AutoSize property will shrink or enlarge the label to fit the text.
Using the AutoSize Property (cont.)
Using the AutoSize Property (cont.)
Declaring Variables Using a variable in your programs 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 Declare a variable Use the  Dim  statement
Rules for Naming Variables When naming variables, keep the following rules in mind: Variable names must begin with an alphabetic character. Following the first character, letters, numbers, and underscores are allowed. Variable names cannot include spaces. Variable names can be 255 characters long.
Rules for Naming Variables (cont.)
Using Variables Variables can be used in the same way as labels and text boxes. Use the assignment operator to assign a value to a variable. You can also assign hard-coded values to a variable.
Using Variables (cont.) Use mathematical operators to perform calculations with numeric variables. Output the value in a variable. Assign the value to a label.
Using Variables (cont.)
Using Variables (cont.)
Scope The term “scope” refers to the reach of a variable. General rule You should declare variables as locally as possible.
Three Levels of Scope Levels Local variable Declared within an event procedure Form-level variable Declared in the Declarations section of a form’s Code window Global variable Declared in a code module’s section
The Declarations Section Access the Declarations section Select (Declarations) from the Method Name list that appears at the top of the Code window.
The Declarations Section (cont.)
The Declarations Section (cont.)
Using the Object Data Type Object data type Very flexible Can store many different types of variables Object variables Can be declared by specifying the Object type Or by declaring a variable without a type
Summary 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 (cont.) The AutoSize property will adjust the size of a control to fit its contents. 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 a good idea to use naming prefixes to identify the data type of the variable.
Summary (cont.) You can assign values to variables using the assignment operator. You can also use the other mathematical operators with numeric variables. A variable’s scope indicates the procedures that have access to the variable. A variable’s scope can be local, form-level, or global.
Summary (cont.) The Declarations section of a form’s Code window allows you to declare form-level variables. The Object data type can hold many different kinds of data, but is less efficient than specific data types.

More Related Content

PPTX
Data types vbnet
PPTX
2018 03 27_biological_databases_part4_v_upload
PPT
User defined data type
PPTX
Grade 9 COMPUTER
PPTX
Numerical data.
PPTX
PPTX
2018 02 20_biological_databases_part2_v_upload
PPTX
Design patterns
Data types vbnet
2018 03 27_biological_databases_part4_v_upload
User defined data type
Grade 9 COMPUTER
Numerical data.
2018 02 20_biological_databases_part2_v_upload
Design patterns

What's hot (6)

PPTX
Swift Generics
PPTX
data types in C programming
PPTX
Concept Of C++ Data Types
 
PPTX
WEKA: The Explorer
PPT
Lect 9(pointers) Zaheer Abbas
PPT
Textmining Predictive Models
Swift Generics
data types in C programming
Concept Of C++ Data Types
 
WEKA: The Explorer
Lect 9(pointers) Zaheer Abbas
Textmining Predictive Models
Ad

Viewers also liked (20)

PPT
PowerPoint Lesson 1
PDF
Les 02 1
PPT
Samenwerkingsproject De Limissie (Linked In)
PPT
NexGen Biosolutions Presentation
DOC
Project management
PPT
Ppt lesson 10
PPT
Ppt lesson 09
PPTX
Mastering python lesson2
DOC
5 lesson 2 1 variables & expressions
PPTX
SmartBoard Lesson Plans
PPT
Primitive Data Types and Variables Lesson 02
PPTX
c++ programming Unit 3 variables,data types
PDF
C++ L01-Variables
PPTX
Eukaryotic Cells -Brief Online Lesson Plan
PDF
Syallabus y1 4
PPTX
Algebraic expressions and terms
PDF
Compilation of ict document year 2
PPT
Variable and Algebraic Expressions
DOCX
Semi Detailed Lesson Plan in Programming Languages
DOCX
Topic Sentence Semi-detailed Lesson Plan
PowerPoint Lesson 1
Les 02 1
Samenwerkingsproject De Limissie (Linked In)
NexGen Biosolutions Presentation
Project management
Ppt lesson 10
Ppt lesson 09
Mastering python lesson2
5 lesson 2 1 variables & expressions
SmartBoard Lesson Plans
Primitive Data Types and Variables Lesson 02
c++ programming Unit 3 variables,data types
C++ L01-Variables
Eukaryotic Cells -Brief Online Lesson Plan
Syallabus y1 4
Algebraic expressions and terms
Compilation of ict document year 2
Variable and Algebraic Expressions
Semi Detailed Lesson Plan in Programming Languages
Topic Sentence Semi-detailed Lesson Plan
Ad

Similar to Ppt lesson 05 (20)

PPTX
Variables and calculations_chpt_4
PPTX
CHAPTER 2 (Data types,Variables) in Visual Basic Programming
PPT
Ppt lesson 07
PPTX
Keywords, identifiers and data type of vb.net
PPTX
Basic C programming Language - Unit 1.pptx
PPTX
INTRODUCTION TO C
PDF
Suncoast Credit Union and Armwood High School - UiPath automation developer s...
PPT
Chapter2pp
PDF
Visual Basics for Application
PPTX
Ch-3(b) - Variables and Data types in C++.pptx
DOCX
Obiee interview questions and answers faq
PPTX
Unit 1 introduction to visual basic programming
DOC
11i&r12 difference
PDF
C programming session7
PDF
C programming session7
PPTX
E learning excel vba programming lesson 3
PPT
Qtp - Introduction to fundamentals of vbscript
PDF
I x scripting
PPTX
Core C# Programming Constructs, Part 1
Variables and calculations_chpt_4
CHAPTER 2 (Data types,Variables) in Visual Basic Programming
Ppt lesson 07
Keywords, identifiers and data type of vb.net
Basic C programming Language - Unit 1.pptx
INTRODUCTION TO C
Suncoast Credit Union and Armwood High School - UiPath automation developer s...
Chapter2pp
Visual Basics for Application
Ch-3(b) - Variables and Data types in C++.pptx
Obiee interview questions and answers faq
Unit 1 introduction to visual basic programming
11i&r12 difference
C programming session7
C programming session7
E learning excel vba programming lesson 3
Qtp - Introduction to fundamentals of vbscript
I x scripting
Core C# Programming Constructs, Part 1

More from Linda Bodrie (11)

PPT
Ppt lesson 12
PPT
Ppt lesson 11
PPT
Ppt lesson 08
PPT
Ppt lesson 06
PPT
Ppt lesson 06
PPT
Ppt lesson 06
PPT
Lesson 5 PP
PPT
Lesson 4 PowerPoint
PPT
Ppt lesson 03
KEY
PowerPoint Lesson 2
PPT
Ppt lesson 01
Ppt lesson 12
Ppt lesson 11
Ppt lesson 08
Ppt lesson 06
Ppt lesson 06
Ppt lesson 06
Lesson 5 PP
Lesson 4 PowerPoint
Ppt lesson 03
PowerPoint Lesson 2
Ppt lesson 01

Ppt lesson 05

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