Adding a Reference
A Reference is a DLL that can be added to a project to add new functionality.
to add a reference click
Project > References...
You can either select a Reference by name or you can use the "Browse" button and navigate to a DLL.
Adding a Component
There are two ways to add a Component
1:
Click (Project > Components...)
2:
Right Click The Toolbox > Components...
after doing either you will have the components box, it works in a similar ways to adding a DLL you can either
select the OCX file from a list or "Browse" for it.
Adding a New Form, Module or Other
To add a new form you can either:
Click (Project > Add #ITEM#)
or
Right Click The Properties Window (Add > #ITEM#)
Making an Executable
To make the Executable file (.exe) also know as Compiling you:
Click (File > Make #ProjectName#.exe)
then specify the location to create the .exe
How to put an Object on a Form
To put an Object on a Form you need to Click the Object you want then click the form in the location you want your
Object, Object's can be moved just by Clicking and Dragging.
The Basics of Coding in Visual Basic 6
First of all, all data in Visual Basic is in its common lowest form (Bytes, Milli-Seconds, Characters(letters))
below i will explain loads of other things in detail.
Data Types
In Visual Basic There are Different Types of data for this tutorial i will list a few and explain them
String's
A String can be anything (Numbers, Symbols, Letters)
there are two types of string, Fixed length and Variable length
Fixed Length:
Size: Length of String
Range: 1 to approximately 65,400 (Max Length)
Example: String1 As String * 255 (make the strings max length 255)
Variable Length:
Size: 10 Bytes + Length of String
Range: 0 to approximately 2 billion
Example: String1 As String
Integer's and Long's
And Integer's amd Long's are both for numbers, with Integer meaning Number and Long Meaning Long Number
Integer:
Size: 2 Bytes
Range: -32,768 to 32,767
Example: Number As Integer
Long:
Size: 4 Bytes
Range: -2,147,483,648 to 2,147,483,647
Example: Number As Long
As you can see, Long's have a much greater range that Integer's, yet are bigger so make sure
you use each at the appropriate time.
Boolean's
A Boolean is very simple it can only contain two anwsers, True or False
Boolean:
Size: 2 Bytes
Range: True and False
Example: Question as Boolean
Byte's
A Byte is as the name says, its a byte.
Byte:
Size: 1 Byte
Range: 0 to 255
Example: Number as Byte
Layout
When Coding in Visual Basic 6, one thing that is good to remember is that most things work like trees for example:
"Root.Tree.Branch"
with each being separated with a "." and the Root being the Form, Module, or whatever the Parent is, The tree being the Object and the Branch being the Property, Function or Sub.
Sometimes it can be
"Root.Tree.Branch.Leaf"
with Leaf being a variable inside a property.
When you’re trying to Access a Tree from inside that Tree's Root then you only need to use
"Tree.Branch" or "Tree.Branch.Leaf"
because Visual Basic will automatically assume that you are trying to access something within the Root that
the code is being executed from, unless you specify otherwise.
Another thing to remember is that a Form can refer to itself as "Me", so in that sense the Root name can be "Me".
In a Sub or Function there are a few things to know
in Sub's and Function's you can have declarations(Parameters) such as:
Function FunctionName(String1 as String, Integer1 as Integer)
also if you have a Function that returns something it can be like
String:
Function FunctionName(String1 as String, Integer1 as Integer) As String
Integer:
Function FunctionName(String1 as String, Integer1 as Integer) As Integer
So when calling a Sub or Function there are two ways two go
1.
Call FunctionName(StringData, IntegerData)
2.
FunctionName StringData, IntegerData
if you notice when there are Brackets () there is a preceding "Call" this is because when using Brackets () Visual Basic
either expects a "=" or a "Call", otherwise Visual Basic will return a "Compile Error:".
What’s the Difference between a "Private" and a "Public"?
a "Private" can only be Called within its Root while a "Public" can be called from anywhere this
goes for Sub's, Functions and Declaration's.
"If" Statements
An "If" statement is basically a True or False question, it must start with an "If" and end with an "End if" and it
may also include an "Else".
for example:
If a = a then
'Yes as does equal its self
Else
'This is impossible
End if
the Else is Optional, also you can have "ElseIf" that is where you have another If with an else, i would
work the same way as another "if" but you wouldn't need an extra "End If".
Comments
A comment is simply a line with a ' at the beginning
Case?
a "Case" is like saying if loads of times.
a "Case" always starts with:
Select Case #DATA#
and ends with End Select
with #DATA# being what is being looked at for example:
Dim CaseObj as String 'Declaration1
Dim Suitcase as string 'Declaration2
CaseObj = "Hello" 'What CaseObj actually is
Suitcase = "Door" 'Just defining Suitcase for the sake of it
Select Case CaseObj
Case SuitCase
'Impossible
Case "Hello"
'Correct
Case "Door"
'Impossible
End Select
now above i made declarations just to give you a better idea of whats happening.
For?
ok a For is a loop but to a specific number
a For always begins with "For" and ends with Next #LETTER# for example
Dim i As Integer
For i = 0 To 10
'code Code code
Next i
Each time the code loops "i" will be one number greater until it reaches 10 and "i"
can be used in the code itself for example
Dim i as Integer
Dim D as String
For i = 0 To 10
D = D & i
Next i
When that code has finished "D" should equal "012345678910", that is because i used & to Append the number to then end,
if "D" were an Integer, i could have used "+" to add "i" to "D"
Message boxes
The Function to call a message box is "Msgbox" here is an example of a message box
Msgbox "Hello", vbOkOnly, "Hello"
or
Call Msgbox("Hello", vbOkOnly, "Hello")
both of the above will look like this:
i will explain a more advanced way of using these later.
Input boxes
The function to call an input box is "Inputbox" this is more complicated than "Msgbox"
The text inputted into the InputBox can be converted into a string, I will show you in "Welcome home"