0% found this document useful (0 votes)
47 views26 pages

Visual Basic Programming: An Introduction

Visual Basic provides an easy way to build graphical user interfaces. It allows drawing controls like buttons and text boxes and adding code to handle user interactions. The code is event-driven and added by double clicking on controls. Visual Basic can also interface with code written in other languages like C/C++ for efficiency. It has limitations in that it is not as powerful, elegant or fast as other languages but makes building Windows applications more approachable.

Uploaded by

apem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views26 pages

Visual Basic Programming: An Introduction

Visual Basic provides an easy way to build graphical user interfaces. It allows drawing controls like buttons and text boxes and adding code to handle user interactions. The code is event-driven and added by double clicking on controls. Visual Basic can also interface with code written in other languages like C/C++ for efficiency. It has limitations in that it is not as powerful, elegant or fast as other languages but makes building Windows applications more approachable.

Uploaded by

apem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Visual Basic Programming

An Introduction
Why Visual Basic?
H Programming for the Windows User
Interface is extremely complicated.
H Other Graphical User Interfaces (GUI) are
no better.
H Visual Basic provides a convenient method
for building user interfaces.
H Visual Basic can interface with code written
in C, for efficiency.
What Visual Basic is not
H Visual Basic is not, a powerful
programming language that enables you to
do anything you want.
H Visual Basic is not, elegant or fast.
H Visual Basic is not, a replacement for C.
H Visual Basic is not, anything like any other
programming language you have ever used.
When You Program in VB:
H You draw pictures of your user interface.
H You draw buttons, text boxes, and other
user-interface items.
H You add little snippets of code to handle the
user interaction.
H You add initialization code, usually as the
last step.
H If you like, you can code more complex
functions. (But many do not.)
The Visual Basic Interface

Draw Your
Program
Here!
Drawing The Program

Select A Control From Here


(Click on the appropriate button)

Then Draw the control on the form


Types of Controls
Static Text Pictures
Group Box Editable Text
Check Box Button
Scroll Bar Radio Button
Drop-Down List List
Timer Scroll Bar
Folder Hierarchy Drive List
Circles and Stuff File List
Pictures Lines
Data Base Access

And the List Goes On and On ...


Adding Code
Control External Event
Name Name

You must Write


The Body
Yourself

What to Do When It Happens


C Definition vs. VB Definition
C:
long FAR PASCAL _export HexToLong (char *Hex)

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.
Syntax Considerations
H All Functions are Global in VB
H Variables are declared using the syntax:
– Dim <Name> As <Type>
– Every variable must have a type
– Dim A,B,C As <Type> will work, but gives
weird results
H Most Common Types: Integer, String, Long
VB IF Statements

If <condition> Then If <condition> Then


<List of Statements> <List of Statements>
Else EndIf
<List of Statements>
EndIf

Comparators: =,<, >, <=, >=, < > (not equal)


Connectives: And, Or, Not

DON’T FORGET THE ENDIF!


VB While Statements

While <condition> do
<List of Statements>
Wend

The VB Manual Recommends a different structure.


Use the alternative if you wish.
VB Arrays
H 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)
Visual Basic Programming

An Introduction
Why Visual Basic?
H Programming for the Windows User
Interface is extremely complicated.
H Other Graphical User Interfaces (GUI) are
no better.
H Visual Basic provides a convenient method
for building user interfaces.
H Visual Basic can interface with code written
in C, for efficiency.
What Visual Basic is not
H Visual Basic is not, a powerful
programming language that enables you to
do anything you want.
H Visual Basic is not, elegant or fast.
H Visual Basic is not, a replacement for C.
H Visual Basic is not, anything like any other
programming language you have ever used.
Drawing The Program

Select A Control From Here


(Click on the appropriate button)

Then Draw the control on the form


Types of Controls
Static Text Pictures
Group Box Editable Text
Check Box Button
Scroll Bar Radio Button
Drop-Down List List
Timer Scroll Bar
Folder Hierarchy Drive List
Circles and Stuff File List
Pictures Lines
Data Base Access

And the List Goes On and On ...


A Simple Program
Double-Click to
Add Code

Single-Click to
Select and
Change
Properties

Using controls: Static Text


Editable Text
Buttons
Using C Code
H 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
C Definition vs. VB Definition
C:
long FAR PASCAL _export HexToLong (char *Hex)

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.
Syntax Considerations
H All Functions are Global in VB
H Variables are declared using the syntax:
– Dim <Name> As <Type>
– Every variable must have a type
– Dim A,B,C As <Type> will work, but gives
weird results
H Most Common Types: Integer, String, Long
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
H 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)
VB Strings
H 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.
And in Conclusion ...

Go
Have
Fun!

You might also like