Visual Basic is a Rapid Application Development language and my RAD language
of choice for windows applications. It is easy to use, yet very powerful
with full access to windows api's you can create almost any windows based
application you can imagine. Even Microsoft is still using Visual Basic for
their current AntiSpyware software.
Creating a new Visual Basic Program is easy. To create a Visual Basic
Exe file use the Standard Exe option.
Click the image below see a picture of the default VB6 Integrated Development
Setting the project Properties dialog. On this page you can select the
startup type, either one of the forms, or using Sub Main.
Here you can set the application title, icon, and version information.
You can also set the version number to auto increment each time you build a
This is the components dialog, which allows you to add additional
components to the toolbox. This is found under the Project Menu then the
This is the references Dialog, here you can references to dll's and type
This is a picutre of the Visual Basic Menu Editor
This is a picture of the Add-In manger where you can toggle what addins are
Decompiling Visual Basic
Decompiling VB is not an easy task, the only really successful VB Decompilers
was DoDi's decompiler for VB 2 and 3.
For Visual Basic 5/6 - Visual Basic has two compiling options default Native
assembly code, or P-Code which is interpreted, P-Code is easier to turn back to
the original code, while native is hard and there currently is no ideal product
that can recover it.
Semi VB Decompiler for VB 5/6 - is a semi visual basic decompiler which can
recover the forms, api's, and P-Code information for events and procedures.
For VB.net is very easy to decompile and there are numerous decompilers for
it, and you can even convert the VB.net code to C# because that is how the .Net
framework is designed.
My Old Visual Basic 6 Guide that I started to write never finished it so
here it is.
what are you going to learn out of this guide?
You are going to learn how to code correctly in Visual Basic.
And maybe pickup a thing or two you did not know before.
I am assuming that you are able to pick a control from the toolbox
and placing it on the form and setting its properties.
I broke up the guide into four parts.
Part1 - The Basics involving writing good code and formats.
Part2 - The Code basic visual basic commands.
Part3 - Advanced Visual Basic - Dealing with Api's and a lot of cool things.
Part 1A: The Basics
An important of being a good Visual Basic programmer is using good names for
and your controls. It may seem like extra work but in the long run, it will
enable you to
code faster and allow yourself and others to understand your own code better.
A rule I use for prefixes is to keep the prefix in lowercase then uppercase the
of the name of the control or file.
Prefixes for files:
prj = Project
frm = Form
mod = Module
cls = class
usr = user control
Prefixes to Common Controls
lbl = Label control
cmd = Command button
img = Image control
pic = Picture box
tmr = Timer
shp = Shape
chk = Checkbox
lst = Listbox
txt = Textbox
opt = Option button (Radio button)
hs = Horizontal scrollbar
vs = Vertical scrollbar
cbo = Combo box
mnu = Menu
sck = Winsock
Bad Names do not use!
Prefixes can also be very useful to you when you are writing out code.
str = String
lng = Long
int = Integer
sng = Single
bln = Boolean
var = Variant
dim stuff as string
stuff=inputbox("Please enter your name")
dim strName as String
strName = inputbox("Please enter your name")
Part 1B. Making your code readable part 2.
You have already learned how prefixes can help making coding faster and easier.
Now lets move on to comments and indenting!
One of the worst things around is finding code that is not indented and or no
sub ProcessNumber(intNumber as integer)
if intnumber= 3 then
if intNumber = 4 then
sub ProcessNumber(intNumber as integer)
If intnumber= 3 then
If intNumber = 4 then
When do you indent?
You also tab once when you begin to code in an event or subroutine.
Then for each if statement, loop, you also indent.
Visual Basic comments begin with ' and can go anywhere that you want
They are useful in explaining your code to yourself and others.
I really wish vb had multi comments like in C++ but it is not too bad.
Leaving white space makes your code easier to read and makes it look cleaner
Part 2: The Code
The fun stuff begins now.
The very first line in all your forms and modules should be
What does Option Explicit do?
Well it forces you to declare all your variables with otherwise would make them
all the variant type.
example so you can not do
for i=0 to 100
You have to first have i declared
Dim i as byte
for i=0 to 100
What are Variables? They hold data that may change when you run your program
Byte = holds numbers from 0 to 255
String = holds characters or letters such as "Hello World! and numbers too
Integer= numbers no decimals from -32,768 to 32,767
Long = numbers no decimals from -2,147,483,647 to 2,147,483,647
Single = Can hold decimal numbers 32bit.
Boolean = holds either True or False
What are constants? They hold data that does not change.
An example of a constant would be
private const Pi = 3.14
What does Private mean?
Private means it can only be accessed in the current form, module, or class.
What does Public and Global mean?
Public means it can be accessed from any form, module, or class
If you make a variable static it will save its value the next time
the sub is run. I suggest you do NOT use this.
IF Then statements
One line if then statement
If condition=True then blnSomething=true
Multi Line if then statement
If condition=true Then
'Your code goes here
Complex IF then else statements
If condition=True Then
If condition=true Then
ElseIf contition2 = True Then
Select Case Statement:
Like the switch statement in c++
What is it good for?
It is good for instances when you have one variable and
do not want to have a million if then statements.
Dim intNumber as integer
select case intNumber
For Next Loop
For i = 0 to 100 step 100
Subs and Functions overview of ByVal and ByRef
By default all visual basic parameters are passed by reference which means you
the memory address and not the value.
dim strReturnValue as string
sub Test2(strRef as String)
What is a Function? A function is a special kind of procedure that returns a
value for instance
private function AddNumbers(ByVal intNumber1 as integer, ByVal intNumber2 as
integer) as integer
AddNumbers = (intNumber1 + intNumber2)
In the example above it shows a message box with the result of 7
You can specify how you want to pass a parameter either by reference (byRef)
or by value (byVal)
You want to use pass by value when you are not going to change the parameter.
sub Example(ByRef strRef as string, ByVal intNumber as integer)
Some Quick Reference:
All Visual Basic functions and commands are listed in the object browser.
It looks like a box with things coming out of it in the toolbar.
Use App.path instead of hardcoded paths.
App.path returns the path to your application
You can use app.previstance to detect if your application is already running.
Part 3: Advanced Visual Basic Information
Section A: Understanding API's
Your guide for Visual Basic Api's is
Once you vist allapi.net
Get Api Viewer 2004 lists tons of VB Api's
Get Api Guide has many Api's and examples of how to use them.
Converting C++ Api's to Visual Basic Api's
VB Integers = C++ Short
VB Longs = C++ Integers
Section B: Pointers
There is a common myth going around that Visual Basic does not support pointers.
This is untrue they are just hidden.
AddressOf - Used for finding addresses of procedures
Section C: Understanding VB's binary data.
Visual Basic stores a string in the following format
Length as integer
Text as String
Bytes take up 1 byte of data.
Boolean takes up two bytes either 00 00 or FF FF
Integer's take up two bytes.
Long takes up four bytes.
Single takes up four bytes.
Double takes up eight bytes.
Section D: Compiling real Dll's in Visual Basic like C++
By default Visual Basic does not make dll's with exports, they just make active
But you can make them in Visual Basic if you can intercept the compiling
You can make your own c2.exe to intercept the parameters being passed to the
real c2.exe then pass that
information plus the def file to create a normal dll with real exports.
Sites to check out:
- a place to post your Visual Basic Articles, Source Code, Game Projects and