Visual Basic Brief Intro
Visual Basic Brief Intro
Visual Basic Brief Intro
An Introduction
Types of Controls
Static Text Group Box Check Box Scroll Bar Drop-Down List Timer Folder Hierarchy Circles and Stuff Pictures Pictures Editable Text Button Radio Button List Scroll Bar Drive List File List Lines Data Base Access
A Simple Program
Double-Click to Add Code Single-Click to Select and Change Properties
Click on Property, and Type In New Value, or Select New Value From Menu.
Adding Code
Control Name External Event Name
Examples:
Spreadsheets Word Processors Web Browsers
Using C Code
Write a DLL in C H Use the _export Property on Appropriate Functions H Write Visual Basic Definitions for each Function H Add VB Definitions to The (general) section of the VB Program H Use Functions as if they were VB functions
H
VB: Declare Function HexToLong Lib FIRSTONE.DLL (ByVal InString As String) As Long Function Name Must Be The Same in Both Declarations. The Lib keyword Must Give The Name of the Library. Argument Name in VB is arbitrary.
Alternative Methods
Some Versions of VB do not allow DLL function definitions in the (general) section of a form. H To Get Around this Problem, Create a new Module (File Menu) H Add the declarations to the (general) section of the module H You can add your own VB functions to the (general) section of a form or a module.
H
Syntax Considerations
All Functions are Global in VB H Variables are declared using the syntax:
H
Dim <Name> As <Type> Every variable must have a type Dim A,B,C As <Type> will work, but gives weird results
H
More VB Syntax
H
Assignments are the same as in C H The Val function converts strings to integers H The Format$ function converts integers to strings
H
VB Statements
Assignments are the Same as in C H Case is not significant
H
Case will be adjusted for you on keywords For Variable Names, Case is ignored
H
VB IF Statements
If <condition> Then <List of Statements> Else <List of Statements> EndIf If <condition> Then <List of Statements> EndIf
Comparators: =,<, >, <=, >=, < > (not equal) Connectives: And, Or, Not
VB While Statements
While <condition> do <List of Statements> Wend
The VB Manual Recommends a different structure. Use the alternative if you wish.
VB For Statements
For <Variable> = <start> to <finish> <List of Statements> Next <Variable> For <Variable> = <start> to <finish> Step <increment> <List of Statements> Next <Variable> Example: For I = 1 to 10 do A[I] = A[I] + 1 Next I
VB Arrays
Indices Always Start With Zero H Dim A[10] As Integer Declares 11 elements, indexed from 0 through 10. H Multi-Dimensional Arrays are Permitted. H Arrays can be resized at run time (See VB Help File for ReDim)
H
VB Strings
Variable Length H Compare using standard comparators H Maximum length is about 64Kb H Minimum length is zero H Allocated from VB String Space, so may run out of space even on systems with much memory.
H
Go Have Fun!
Types of Controls
Static Text Group Box Check Box Scroll Bar Drop-Down List Timer Folder Hierarchy Circles and Stuff Pictures Pictures Editable Text Button Radio Button List Scroll Bar Drive List File List Lines Data Base Access
A Simple Program
Double-Click to Add Code Single-Click to Select and Change Properties
Click on Property, and Type In New Value, or Select New Value From Menu.
Adding Code
Control Name External Event Name
Examples:
Spreadsheets Word Processors Web Browsers
Using C Code
Write a DLL in C H Use the _export Property on Appropriate Functions H Write Visual Basic Definitions for each Function H Add VB Definitions to The (general) section of the VB Program H Use Functions as if they were VB functions
H
VB: Declare Function HexToLong Lib FIRSTONE.DLL (ByVal InString As String) As Long Function Name Must Be The Same in Both Declarations. The Lib keyword Must Give The Name of the Library. Argument Name in VB is arbitrary.
Alternative Methods
H
Some Versions of VB do not allow DLL function definitions in the (general) section of a form. H To Get Around this Problem, Create a new Module (File Menu) H Add the declarations to the (general) section of the module H You can add your own VB functions to the (general) section of a form or a module.
Syntax Considerations
All Functions are Global in VB H Variables are declared using the syntax:
H
Dim <Name> As <Type> Every variable must have a type Dim A,B,C As <Type> will work, but gives weird results
H
More VB Syntax
H
Assignments are the same as in C H The Val function converts strings to integers H The Format$ function converts integers to strings
H
VB Statements
Assignments are the Same as in C H Case is not significant
H
Case will be adjusted for you on keywords For Variable Names, Case is ignored
H
VB IF Statements
If <condition> Then <List of Statements> Else <List of Statements> EndIf If <condition> Then <List of Statements> EndIf
Comparators: =,<, >, <=, >=, < > (not equal) Connectives: And, Or, Not
VB While Statements
While <condition> do <List of Statements> Wend
The VB Manual Recommends a different structure. Use the alternative if you wish.
VB For Statements
For <Variable> = <start> to <finish> <List of Statements> Next <Variable> For <Variable> = <start> to <finish> Step <increment> <List of Statements> Next <Variable> Example: For I = 1 to 10 do A[I] = A[I] + 1 Next I
VB Arrays
Indices Always Start With Zero H Dim A[10] As Integer Declares 11 elements, indexed from 0 through 10. H Multi-Dimensional Arrays are Permitted. H Arrays can be resized at run time (See VB Help File for ReDim)
H
VB Strings
Variable Length H Compare using standard comparators H Maximum length is about 64Kb H Minimum length is zero H Allocated from VB String Space, so may run out of space even on systems with much memory.
H
Go Have Fun!