Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home4/sambenne/public_html/samsvb/includes/dbc.php on line 3
Visual Basic 6 Tutorials

Lesson 1 Getting to know VB6.

The VB6 IDE (Integrated Development Environment) is a very simple and fully featured IDE. If you start out programming in VB6 you may end up being too spoiled to ever appreciate a more complicated and less functional IDE like most C++ IDEs. One feature which sets VB6 apart from various IDEs is the simplicity of its approach to GUI (Graphical User Interface) design.

As a general rule: Play with it. You're very unlikely to break anything that matters, so just explore and experiment with the IDE, and you'll learn more.

Creating A Project


1.Start VB6
2.When presented with a "New Project" dialog you will usually want to pick "Standard EXE" and press "OK"
3.You now see the VB6 IDE, which contains an empty form called "Form1". That is your program.
Example menu

Description of the IDE

In the middle of the program is a window which contains another window called "Form1". This is called the GUI designer window. That window inside of there with the title "Form1" is your program.

Example form

On the left is the toolbox, which stores the pre-made objects you can place in your program. This includes visual items you often see in programs like textboxes, command buttons, checkboxes. It also has the potential to include invisible items like the winsock control, which allows easy access to network communication.

Example tutorial

On the right is the Object properties pane, which contains all of the properties of the item currently selected in the GUI designer.

Example properties window Example project window

On the top there is the menu bar.

On the top, below the menu bar is the toolbar.

Example toolbar

Setting up the IDE

Don't allow sloppiness


1.Click on Tools->Options
2.Check "Require Variable Declaration"
3.Click on the "Environment" tab
4.Select the option button which says "Prompt to save changes"
5.Press "OK"

Get rid of silliness

On the bottom-right of the IDE, close the "Form Layout" pane because its pretty much useless.

Access to handy functions


1.Right-click somewhere on the toolbar and click on "Customize..."
2.Click on the "Commands" tab
3.Under "Categories", select "Edit"
4.Scroll down to about the middle of the "Commands" box until you can see "Indent", "Outdent", "Comment Block", and "Uncomment Block". Drag all of those items to your toolbar, putting them in order, right next to the "Start", "Pause", and "Stop" buttons.
5.Press "Close"

You can now use these commands by selecting a block of text in your source code then hitting one of these commands to do the specified function on the whole block of code. Handy.

Changing Properties of Objects

If you click on an object on your form, or even the form itself, you gain access to the properties of that item and change them in the properties pane on the right side of the screen.

Using controls

Placing controls on a form

All of the items on the left-hand of the screen, in the toolbox pane, are able to be added to a form like this:


1.Click on the box representing the control you want in your program


2.Click the left mouse down on a space on a form, then drag to another spot and release the left mouse button. This sometimes makes the control you selected the same size as you directed, and sometimes objects are a fixed size which you can't modify

Importing extra controls

If you want to use a control which is not included in VB6's "Standard EXE" toolbox of 21 controls, you'll need to import them like this:


1.Right-click somewhere in the toolbox, and select "Components"
2.In that window you can select an OCX file which contains controls you can add to your form

If the control you're looking for isn't on the list then you can try to find it by clicking "Browse..." and finding the OCX file manually

Sometimes OCX files are given the extension DLL when the file is a DLL which includes OCX data inside it

Underlined letters

When you press the Alt button in many programs you're shown little lines underneath certain letters of menu items. If you then press on your keyboard a letter which corresponds to one of the underlined letters then that menu item is selected.

In VB6, to get that functionality all you have to do is place an apersand (&) the letter before the letter you want to be underlined and functional in this way.

This functionality exists in:

Primary Menu items

Secondary menu items

Command buttons

More..?

Running A Program

Take a look in the menu item "Run".

You will find that:

Pressing "Start" in that menu, pressing the "Play" button, or pressing F5 on your keyboard will run your program

Pressing "Break" in that menu, pressing the "Pause" button, or pressing Ctrl+Break on your keyboard will pause your program

Allows you to edit your program while you're running it (AWESOME! Spoilage factor here versus every other programming IDE)

Pressing "End" in that menu, or pressing the "Stop" button will stop your program

Stopping A Program

When you are done testing your application, you will want to close it. There are several ways to accomplish this.

If at all possible you should close your application by pressing the "X" button on the top-right of the window of an application, or using the keystroke Alt+F4. This is a "clean" termination of the program.

The following options should be used only in the case that your program has stalled and you cannot close it by pressing Alt+F4 or the "X" button on the program's window. In all of these options there is a chance of causing a memory leak, which renders some space in your computer's memory unusable until the next time you reboot the computer.

If the VB6 IDE is still responsive: Press the "Stop" button located beside the "Play" and "Pause" buttons in the VB6 IDE.

If the VB6 IDE is no longer responsive: Press Ctrl+Break to Pause the program's execution.

If Ctrl+Break doesn't work: Try to end VB6.exe via the windows task manager.

If none of that works: Time to restart the computer and go fix that horrible bug in your program!

Compiling A Program

You must be using a full, retail copy of Visual BASIC. The Learning Edition will not compile to EXE

In the VB6 IDE, press File->Make ProjectName.exe, select a location and filename you would like your

program to have and VB6 will create that EXE for you simply and very easily.

The process in which source code is converted into EXE is called "compiling", and is far more simplified in VB6 than a language like C++.

In order for your program to run on any given computer, that computer must have all of your program's "dependencies". All programs written in VB6 will require the Visual Basic 6 Runtime Library (msvbvm6.dll). Happily: Windows XP had the VB6 runtime library ever since first release, so if you make a VB6 program with no extra dependencies, it will work on Windows XP.

Prior versions of windows, however, did not come with the VB6 runtime preloaded, and will require it to be installed if it hasn't yet been installed.

If your program requires any extra DLL or OCX files in order to work, those are now dependencies of your program which you will need to supply to anyone you want to send your program to. For maximum portability it is a good idea to rely on functionality you implement in your own program. If you're lucky, you can opt for implementing the CTL source code file from an OCX into your program if the OCX is open-source and was written in VB6.

Getting into the source code

Right-click anywhere on the form called "Form1", and select "View code". Another way to accomplish the same thing is to double-click anywhere on the form.

You should now see the following:


1.Private Sub Form_Load()
2.End Sub

This is the current source code behind this form. Your cursor is currently between "Private Sub Form_Load()" and "End Sub" because the object you double-clicked on was a "Form" and the default subroutine for the IDE to bring you to if there is nothing yet coded for that object is "Load()".

You can change which subroutine associated with "Form" you want to look at by clicking somewhere inside the "Form_Load" routine, then selecting one of the options inside the combo-box on the top right of the window you're in.

This function will get you spoiled, quick.

Setting project properties

In the top menu click on Project >> Project1 Properties

Search through this dialog. Learn its options. Set the values inside.


(More Images coming soon)

Short cuts