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.
Numeric data types support mathematical operations. These include:
These types do not support mathematical operations. Common examples include:
Suffixes specify the data type of a literal value, allowing more accurate computations. Examples:
&
for Long!
for Single#
for Double@
for CurrencyAlso, enclose string literals in quotes and date literals within #
symbols.
memberName = "Turban, John" TelNumber = "1800-900-888-777" LastDay = #12/31/2000# ExpTime = #12:00 AM#
Variables are placeholders for storing data in memory. You must name and declare them correctly for effective program design.
!, @, &, $
.Valid Names | Invalid Names |
---|---|
My_Car | My.Car |
ThisYear | 1NewBoy |
Long_Name_Can_beUSE | He&HisFather |
Use Dim
for local variables, and combine multiple declarations using commas. Example:
Dim name As String, age As Integer, score As Double
Fixed-length strings use:
Dim yourName As String * 10
Dim
: Local scopePrivate
: Module-level visibilityPublic
: Global scopeStatic
: Remembers values between procedure callsConstants hold values that do not change during program execution. Declared using the Const
keyword.
Const Pi As Single = 3.142
Uses a constant and several variables to compute the circle’s area based on user input.
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 a = Pi * rad ^ 2 area = Round(a, 2) MsgBox ("The Area of the circle is " & area) End Sub Private Sub CmdResize_Click() h = InputBox("Enter the value of height") MyShape.Height = h End Sub
Dim
, follow naming rules strictly.Dim
, Private
, Public
, Static
.Const
to store unchangeable values.Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy
Last update:06/02/2025 08:08:11