Lesson 5: Managing VB Data
Master VB6 data management to create efficient applications with proper data handling and storage techniques
Key Takeaway
Understanding VB6 data types and proper variable management is crucial for creating efficient, error-free applications. Mastering data types helps optimize memory usage and prevent runtime errors.
Welcome to Lesson 5 of our Visual Basic 6 Tutorial! In this lesson, you'll learn how to effectively manage data in VB6 applications. We'll cover data types, variables, constants, and scope with practical examples you can implement.
5.1 Understanding Visual Basic 6 Data Types
Data types in VB6 are essential for managing information effectively in applications. They are broadly categorized into numeric and non-numeric data types. This classification helps developers write efficient and accurate code.
5.1.1 Numeric Data Types in VB6
Numeric data types support mathematical operations. These include:
1 Integer Types
Byte: Unsigned 8-bit number (0 to 255)
Integer: 16-bit signed integer (-32,768 to 32,767)
Long: 32-bit signed integer (-2.1B to 2.1B)
2 Floating-Point Types
Single: 32-bit floating-point
Double: 64-bit floating-point
Currency: 64-bit fixed-point
Decimal: 96-bit high-precision
Important Note
Always choose the smallest data type that can accommodate your values to conserve memory. Use Currency for financial calculations to prevent rounding errors.
5.1.2 Non-Numeric Data Types in VB6
These types do not support mathematical operations. Common examples include:
String
Text values, can be fixed or variable length
Date
Stores date and time values
Boolean
True/False values
Variant
Flexible but less efficient
5.1.3 Using Suffixes for Literals in VB6
Suffixes specify the data type of a literal value, allowing more accurate computations:
Suffix | Data Type | Example |
---|---|---|
& |
Long | 12345& |
! |
Single | 3.14! |
# |
Double | 3.1415926535# |
@ |
Currency | 19.99@ |
Also, enclose string literals in quotes and date literals within #
symbols.
Private Sub Form_Load() Dim memberName As String Dim TelNumber As String Dim LastDay As Date Dim ExpTime As Date memberName = "Turban, John" TelNumber = "1800-900-888-777" LastDay = #12/31/2000# ExpTime = #12:00 AM# End Sub
5.2 Working with Variables in VB6
Variables are placeholders for storing data in memory. You must name and declare them correctly for effective program design.
5.2.1 Naming Rules for Variables
Follow these rules when naming variables in VB6:
No Spaces
Variable names cannot contain spaces
Start with Letter
Must begin with a letter
No Special Characters
Avoid !, @, &, $, etc.
Length Limit
Must be less than 255 characters
Examples:
Valid Names | Invalid Names |
---|---|
My_Car | My.Car |
ThisYear | 1NewBoy |
Long_Name_Can_beUSE | He&HisFather |
5.2.2 Declaring Variables Explicitly
Use Dim
for local variables, and combine multiple declarations using commas:
Private Sub Command1_Click() ' Declare multiple variables on one line Dim name As String, age As Integer, score As Double ' Fixed-length string declaration Dim yourName As String * 10 End Sub
5.2.3 Variable Scope in VB6
Variable scope determines where in your program a variable can be accessed:
1 Local Scope
Declared with Dim
within a procedure
Only accessible within that procedure
2 Module Scope
Declared with Private
in declarations section
Accessible to all procedures in the module
3 Global Scope
Declared with Public
in declarations section
Accessible throughout the application
4 Static Variables
Declared with Static
Retains value between procedure calls
5.3 Working with Constants
Constants hold values that do not change during program execution. Declared using the Const
keyword.
' Declare a constant for Pi Const Pi As Single = 3.142 ' Declare a string constant Const AppName As String = "VB6 Data Manager"
Practical Example: Calculate Area of a Circle
This program calculates the area of a circle using a constant and variables. The user can resize the circle shape and calculate its area.
' Declare variables and constant Dim h, r, a, rad, area As Single Const Pi As Single = 3.142 Private Sub CmdArea_Click() r = h / 2 rad = r * 0.001763889 ' Convert to meters a = Pi * rad ^ 2 ' Area = πr² area = Round(a, 2) ' Round to 2 decimal places ' Show result in a message box MsgBox ("The Area of the circle is " & area) End Sub Private Sub CmdResize_Click() ' Get height from user h = InputBox("Enter the value of height") ' Resize the circle shape MyShape.Height = h End Sub
Circle Area Simulation:

Lesson Summary
In this lesson, you've mastered essential VB6 data management techniques:
Data Types
Learned numeric and non-numeric data types and their appropriate uses
Variable Declaration
Mastered declaring variables with proper naming conventions
Scope Management
Understood variable scope and how to control it with Dim, Private, Public
Constants
Implemented constants for fixed values that don't change during execution
You've now built a solid foundation in VB6 data management and are ready to explore variables in more depth in the next lesson.
Next Lesson
Continue your VB6 journey with Lesson 6: Variables.
Related Resources

Visual Basic 6 Made Easy
The ultimate beginner-friendly guide for mastering Windows-based application development using Visual Basic 6. Used as a textbook by universities worldwide.
What You'll Learn:
- Comprehensive coverage of VB6 coding techniques
- Event-driven programming best practices
- Practical examples and projects
- Debugging and error handling
- Database integration
- Advanced UI development

Visual Basic 2022 Made Easy
The ultimate guide to VB.NET programming in Visual Studio 2022. Master modern VB development with this comprehensive resource.
What You'll Learn:
- Modern VB.NET coding techniques
- Visual Studio 2022 features
- Advanced UI development
- Database programming with ADO.NET
- Web API integration
- Deployment strategies