Visual Basic 6 Basic's
Volume 1

By BrandiniMP
Welcome to my Visual Basic 6 guide
In this segment I will explain the basics of using Visual Basic 6 (VB6) and
the basics of coding in Visual Basic 6.
Download Visual Basic 6
click here to download Service Pack 6 for VB6

RAR Password: http://crazy-coderz.net
Size: 74299 KB

         Download
A Brief History of Visual Basic

Visual Basic 6 was created by Microsoft in mid 1998 and became obsolete after the release
of VB .NET, although obsolete, many coders still use it and Microsoft still has some support.

Although the main support for Visual Basic 6 was ceased in 2005 Microsoft has continued
to give a small amount of support for it, until March 2008 whereas Microsoft Ceases all
support for Visual Basic 6.

Visual Basic is a RAD (Rapid Application Development) tool designed to help developers
produce fast and effective applications quickly and easily.

The Basics of using Visual Basic 6

How things work in VB6
A - Objects

The objects are a vital part of Visual Basic, they are the things that you place on forms
to run functions and execute commands.
  
Objects can be added by adding an OCX file to the project, ill will explain how to do this
later.
  

B - The Toolbox

The Toolbox is where all the Objects are displayed, Objects can be selected and used in Projects.
  
C - The Form

     The Form is the visual part of Visual Basic, it is where Objects are placed, The Form is also the window and can be used to Resize, Minimize and Close the application.
  
D - The Workspace
  
The Workspace is basically where the form goes, it helps allow you to resize the form on the visual side of things.
  
E - The Project Explorer

The Project Explorer displays your project, things such as Forms, Modules, Class Modules and User Controls.
  
F - The Code Window

F1 - This is where the code is entered and edited, the code being, Sub's Functions, Variables, Declarations,
         API Calls and more, a few of these will be explained later.
  
    F2 - This is to help you when adding code to objects, this Dropdown Box contains the Objects on that form.

          If you are currently not in the code window of a form, or not in the code for an Object this will simply display "(General)", when you click this it will take you to the code of that object.
       
    F3 - This is where all the individual Sub's are, if you are in side an object or have used the box to its left (as               found in F2) the Dropdown box will display the Sub's for the specified Object, if not in an Object it will display all the other Sub's and Function's.
      
G - The Form Layout Window

This window is designed to give an easier approach to setting the Start-Up position of a specific Form.
  
H - The Object Browser

      The Object Browser can be opened by clicking (View > Object Browser) or by pressing the key "F2".
  
H1 - This lists the Constant's, Type's, Module's, Form's and other things in the project, or
        contained by DLL's and OCX's attached to the project.
  
H2 - This lists the "Members" of a set of Constant's, Type's, Module's Form's and other things in the project

        The "Members" being the Properties that can be set and returned or Function's and Sub's that can be                executed.

H3 - Displays the Function or Sub name and sometimes what it does.

H4 - Is just a search box, so you can search something and the box (H2) will display all the matches.
  
I - Properties

This box displays all the properties of an Object, details about these properties can be found in the Object Browser.
  
J - The Standard Toolbar

    This Toolbar contains things such as: Save, Open, Run, End and other things, things can be added for example I added a "Make Project.exe" Button.
K - Drop Down's

These are just the typical Dropdown Menu's, these are simple enough to use and the options are typically self-explanatory.

L - The Immdiate

This is the "Immediate" it is where debug data is sent when running an application in debug mode, the command Debug.Print is used to add text to it.
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"
Ok, now thats over with, we will do a little tutorial, i call it "Welcome Home"

1. Make a new project.
2. on the form add a New Command Button (Object)

3. now double click the form itself, inside Form_Load put the code:

    Command1.Caption = "Click Me!"
  
4. Double Click the new command button and inside add the code:

Dim Msgboxx As Integer
Dim Inputboxx As String
Dim i As Integer
  
    Inputboxx = InputBox("What is your name?")
    Msgboxx = MsgBox("Welcome Home " & Inputboxx & "." & vbNewLine & "Would you like to see what happens next?", vbYesNo)
  
    If Msgboxx = vbYes Then
    Me.Caption = "Welcome Home " & Inputboxx & ", Well done you just changed my caption."
    Else
    Form1.Caption = Inputboxx & ", You clicked NO!"
    End If
  
    Command1.Caption = ""
    For i = 0 To 10
    Command1.Caption = Command1.Caption & i
    Next i
  
5. now run your application and see what happens

Feedback
Email

Subject


Message
 
Copyright ©2007 Brandon McLeod-Parram
and thats the end of my tutorial, thanks for reading.
Pagerankpagerank checker
Visual Basic 6 is a RAD (Rapid Application Development) tool designed to create prefessional programs in a small amount of time, Visual Basic 6 is Object Orientated, this allows users to develop the GUI (Graphic User Interface) with ease, objects can be interfaced with using code, this will be explained in a later guide.