|
| |
Introduction
 | Visual Basic 6 (VB6) is a Microsoft product with a lineage since
1991. |
 | VB6 is an object-based programming environment. While it has a
number of object oriented features, it is not a "complete" object oriented
development environment. |
 | |
 | VB6 is one of the most popular Windows software development tools. |
 | VB6 is built around an integrated development environment (IDE) that
allows rapid development of user interfaces and the supporting code. |
 | VB has spawned a number of variants including VBScript for web
applications (browser and server). |
 | VB.Net has been released as a "replacement" for VB6 although Microsoft has
promised VB6 product support until 2008. |
Language Fundamentals
Program Structure and Organization
 | VB6 programs are organized by global declarations, functions, and
subroutines. |
 | Source files are ASCII text, but must be edited via the IDE. The
source file contains code to define graphic and program objects developed in
the IDE (e.g., buttons, text boxes, etc.). |
 | Program structure
 | Declarations : functions and subroutines
 | Functions: function fname (p as type, ...) as type |
 | Subroutines: sub subname (p as type) |
|
 | Commenting code: a single quote ' enables a comment. |
 | VB6 is a line oriented language |
|
 | Language/character sets: execution character sets can vary based on
Windows environment; development environment is ASCII text. |
 | Identifiers and keywords: VB6 has a number of key words and identifiers. |
 | VB6 programs are organized into projects (defined as a project files; .prj);
supporting files define windows (form files; .frm), global files (.bas), and a
number of other supporting files for class/object declarations and so forth. |
 | VB6 programs are compiled to machine language. They depend on a set
of supporting DLLs to run even the most basic of applications. VB6 can
also be used to create the following:
 | ActiveX objects |
 | Dynamic Link Libraries (DLLs) |
|

Data Types
Data Type
|
Storage Size
|
Range
|
|
Byte
|
1 byte
|
0 to 255
|
|
Boolean
|
2 bytes
|
True or false
|
|
Numeric data (including date/time)…
|
|
Integer
|
2 bytes
|
-32,768 to 32,767
|
|
Long
(long integer)
|
4 bytes
|
-2,147,483,648 to 2,147,483,647
|
|
Single
(single-precision floating-point)
|
4 bytes
|
-3.402823E38 to -1.401298E-45 for negative
values;
1.401298E-45 to 3.402823E38 for positive
values
|
|
Double
(double-precision floating-point)
|
8 bytes
|
-1.79769313486232E308 to -4.94065645841247E-324 for negative values;
4.94065645841247E-324 to
1.79769313486232E308 for
positive values
|
|
Currency (scaled integer)
|
8 bytes
|
-922,337,203,685,477.5808 to
922,337,203,685,477.5807
|
|
Decimal
|
14 bytes
|
+/-79,228,162,514,264,337,593,543,950,335
with no decimal point;
+/-7.9228162514264337593543950335 with 28
places to the right of the decimal;
smallest non-zero number is +/-0.0000000000000000000000000001
|
|
Date
|
8 bytes
|
January 1, 100 to December 31, 9999
|
|
Object Reference…
|
|
Object
|
4 bytes
|
Any Object reference
|
|
String or text data…
|
|
String (variable-length)
|
10 bytes + string length
|
0 to approximately 2 billion
|
|
String (fixed-length)
|
Length of string
|
1 to approximately 65,400
|
|
Variant data (can be anything)…
|
|
Variant (with numbers)
|
16 bytes
|
Any numeric value up to the range of a Double
|
|
Variant (with characters)
|
22 bytes + string length
|
Same range as for variable-length String
|
|
User-defined (using Type)
|
Number required by elements
|
The range of each element is the same as the
range of its data type.
|
 | Variables are declared via the "dim" statement. Application
level or global variables are defined by the "global" keyword. |
 | VB6 will allow you to create programs in which variables do not have to be
declared. These variables are dynamically scoped during compilation as
Variant data types. |
 | Variable scope:
 | Variables within functions and subroutines are limited to the life of
the structure. |
 | Form level variables exist while the form is open. |
 | Application level variables can be declared for the life of the program. |
|
 | Arrays: VB6 supports multi-dimensional arrays of all data types.
Arrays can be extended at runtime and data preserved. |

Expressions and Operators
Arithmetic
Operators used to perform mathematical calculations.
 |
^ —Exponent Operator |
 |
* —Multiply Operator |
 |
/
—Division Operator |
 |
\ —Division, Return Integer Operator |
 |
Mod —Modulo Operator |
 |
+ —Add
Operator |
 |
-
—Subtract Operator |
Comparison operators
 |
= —Equal
|
 |
<> —Not Equal |
 |
< —Less Than |
 |
> —Greater Than |
 |
<= —LessThan or Equal |
 |
>= —Greater Than or Equal |
Concatenation operators used to combine strings.
 |
+, & for
combining strings |
Logical Operators
 |
And Operator |
 |
Not Operator |
 |
Or Operator |

Control Statements

Input/Output
VB6 is a windows-based development environment.
The VB6 input/output is determined via window forms that include a variety of
built-in or intrinsic objects including:
 | Form including the ability to add menus (with submenus) |
 | Text input box |
 | Radio buttons |
 | Check boxes |
 | List and drop down lists |
 | Command button |
 | Horizontal and scrolling bars |
 | Picture and image controls (hold and display graphics) |
 | File objects (drives, directories, and files) |
 | Frames containers to hold other objects |
 | Basic database object |
In addition to the above objects, the VB6 professional set of controls and
third-party ActiveX controls enable developers to add a number of capabilities
including:
 | Grid structures |
 | Rich text controls |
 | Special purpose controls, API interfaces |
 | Database controls |
VB6 also includes:
 | File I/O: basic functions to open and close files; input, output, and
append to files. There are a number of functions to read and write
single characters/bytes, lines, records, and entire files. |
 | Database: interface to database interface libraries such as ActiveX Data
Objects (ADO). |

Libraries and Support
VB6 includes a rich built-library of support routines and functions
including:
 | String handling |
 | Date and time |
 | Formatting |
 | Math functions |
 | Financial |
The following table summarizes many of the built-in functions provided by
VB6:
| Category |
Keywords |
| Array handling |
Array
Dim, Private, Public,
ReDim
IsArray
Erase
LBound, UBound |
| Assignments |
Set |
| Conversions |
Abs
Asc, AscB, AscW
Chr, ChrB, ChrW
CBool, CByte
CCur, CDate
CDbl, CInt
CLng, CSng, CStr
DateSerial, DateValue
Hex, Oct
Fix, Int
Sgn
TimeSerial, TimeValue |
| Dates/Times |
Date, Time
DateAdd, DateDiff, DatePart
DateSerial, DateValue
Day, Month, MonthName
Weekday, WeekdayName, Year
Hour, Minute, Second
Now
TimeSerial, TimeValue |
| Formatting Strings |
Format
FormatCurrency
FormatDateTime
FormatNumber
FormatPercent |
| Input/Output |
InputBox
LoadPicture
MsgBox |
| Literals |
Empty
False
Nothing
Null
True |
| Math |
Atn, Cos, Sin, Tan
Exp, Log, Sqr
Randomize, Rnd |
| Miscellaneous |
Eval Function
Execute Statement
RGB Function |
| Strings |
Asc, AscB, AscW
Chr, ChrB, ChrW
Filter, InStr, InStrB
InStrRev
Join
Len, LenB
LCase, UCase
Left, LeftB
Mid, MidB
Right, RightB
Replace
Space
Split
StrComp
String
StrReverse
LTrim, RTrim, Trim |
| Variants |
IsArray
IsDate
IsEmpty
IsNull
IsNumeric
IsObject
TypeName
VarType |
Resources
References
Tutorials
|