Programming Languages
A Dave Hillman Project

[Home] [Contact Me] [Site Map] [Search] [References]

Visual Basic 6.0

 

[Up]

[Language Basics]
[C Language]
[C++]
[C#]
[Java]
[JavaScript]
[Visual Basic 6.0]
[VBScript]
[VB.Net]
[.Net Technology]

 

 

Introduction

bulletVisual Basic  6 (VB6) is a Microsoft product with a lineage since 1991.
bulletVB6 is an object-based programming environment.  While it has a number of object oriented features, it is not a "complete" object oriented development environment.
bullet 
bulletVB6 is one of the most popular Windows software development tools.
bulletVB6 is built around an integrated development environment (IDE) that allows rapid development of user interfaces and the supporting code.
bulletVB has spawned a number of variants including VBScript for web applications (browser and server).
bulletVB.Net has been released as a "replacement" for VB6 although Microsoft has promised VB6 product support until 2008.

Language Fundamentals

Program Structure and Organization

bulletVB6 programs are organized by global declarations, functions, and subroutines.
bulletSource 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.).
bulletProgram structure
bulletDeclarations : functions and subroutines
bulletFunctions: function fname (p as type, ...) as type
bulletSubroutines: sub subname (p as type)
bulletCommenting code: a single quote ' enables a comment.
bulletVB6 is a line oriented language
bulletLanguage/character sets: execution character sets can vary based on Windows environment; development environment is ASCII text.
bulletIdentifiers and keywords: VB6 has a number of key words and identifiers.
bulletVB6 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.
bulletVB6 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:
bulletActiveX objects
bulletDynamic 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.

 

bulletVariables are declared via the "dim" statement.  Application level or global variables are defined by the "global" keyword.
bulletVB6 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.
bulletVariable scope:
bulletVariables within functions and subroutines are limited to the life of the structure.
bulletForm level variables exist while the form is open.
bulletApplication level variables can be declared for the life of the program.
bulletArrays: 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.

bullet

^  —Exponent Operator

bullet

* —Multiply Operator

bullet

 /  —Division Operator

bullet

\ —Division, Return Integer Operator

bullet

Mod —Modulo Operator

bullet

 + —Add Operator

bullet

 - —Subtract Operator

 Comparison operators

bullet

 = —Equal

bullet

<> —Not Equal

bullet

< —Less Than

bullet

> —Greater Than

bullet

<= —LessThan or Equal

bullet

>= —Greater Than or Equal

 Concatenation operators used to combine strings.

bullet

 +, & for combining strings

 Logical Operators

bullet

And Operator

bullet

Not Operator 

bullet

Or Operator

Control Statements

bulletIf-then
bulletStandard if-then-else implementation.
bulletDoes not short circuit on complex logical expressions.
bulletExamples:

if (expression) then statement

if (expression) then
    statement
else
    statement
end if

if (expression) then
    statement
elseif (expression) then
    statement
end if

 

bulletSelect
bulletSimilar to a switch statement in C
bulletExample:

select expression
    case expression1
        statement
    case expression2
        statement
end select

 

bulletDo/While loop
bulletStandard looping mechanism.
bulletExamples

do while/until (expression)
    statement
    statement
loop

do
    statement
    statement
loop while/until (expression)

While condition
    statement
Wend

 

bulletFor loop
bulletStandard for/next loop
bulletMay also be used to iterate through a collection of objects (For/Each)
bulletExample:

for expression = value to endvalue step value
    statement
    statement
next

 

bulletGo To: jump to a labeled destination; within a subroutine or function only.
bulletExit: break out of  a loop,  subroutine, or function.

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:

bulletForm including the ability to add menus (with submenus)
bulletText input box
bulletRadio buttons
bulletCheck boxes
bulletList and drop down lists
bulletCommand button
bulletHorizontal and scrolling bars
bulletPicture and image controls (hold and display graphics)
bulletFile objects (drives, directories, and files)
bulletFrames containers to hold other objects
bulletBasic 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:

bulletGrid structures
bulletRich text controls
bulletSpecial purpose controls, API interfaces
bulletDatabase controls

VB6 also includes:

bulletFile 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.
bulletDatabase: 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:

bulletString handling
bulletDate and time
bulletFormatting
bulletMath functions
bulletFinancial

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

bulletMicrosoft VB6 Reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbstartpage.asp
bulletGoogle Directory: http://directory.google.com/Top/Computers/Programming/Languages/Visual_Basic/

Tutorials

bullet http://spazioinwind.libero.it/vbprogzone/tutorials/learnvb1.html

 

 

[Home] [Language Basics] [C Language] [C++] [C#] [Java] [JavaScript] [Visual Basic 6.0] [VBScript] [VB.Net] [.Net Technology]

Copyright © 2003-2005 by Dave Hillman