Beginning
Overview
IDE
Projects
Forms
Controls
Intrinsic Ctrls
ActiveX Ctrls
Code
Commands
Cmd Reference
File Handling
Printing
Distribution

Intermediate
Menus
Dialogs
Mouse
Drag and Drop
Graphics
Error Handling
Databases
Database Controls
SQL

Advanced
API
Objects
Internet File Transfers
UNIX/CGI/Perl
Perl Commands
JavaScript
Web Page Forms

GBIC >> VB >> Tutorials >> IDE
IDE
It's a little known fact, but you can write a VB program from scratch using nothing more than a simple text editor, such as the Edit or Notepad applications which come with Windows. In fact, the Visual Basic project files are exactly that - text files. However, writing a project from scratch would involve a lot of tedious, detailed manual entries. To simplify the task, Microsoft has built in to VB a software program to help you write your VB projects. That software, known as the Integrated Development Environment (IDE for short) is what comes to the screen when you start VB and is the topic of this section.


Overview

Like any other Windows application, VB consists of multiple windows which appear at startup. The windows that are displayed when you start VB are collectively known as the Visual Basic Integrated Development Environment (IDE).

When you first start VB all of the windows are locked together in what is called the MDI format. I prefer the SDI format (which you can set in the options menu) which allows each of the windows to be positioned independently on your screen. Here's a sample IDE screen which shows a VB project with one form on which is a single command button.

(click to enlarge)

In particular, VB has the following windows:

  • Menu / Toolbar
    This is the only element of the IDE which is always visible. You use it to select which other IDE elements to view and to add forms or controls to your project. There are many other features which we will discuss later.

    (click to enlarge)

  • Toolbox
    The toolbox is simply a library of controls which you can place on your application. Once you've placed all the controls you need onto your applications forms, you can hide the toolbox to make room for working in the other elements of the IDE.

  • Project Window
    This is simply a list of all the forms which make up your VB project. There are several kinds of forms which we'll talk about later.

  • Property Window
    We'll talk about controls later, but such things as push-buttons, scrolling text boxes, pictures boxes and other features of most VB applications allow you to enter parameters which define how these controls work. In VB, these parameters are called properties. Some properties can be entered at design time within the IDE, while others must be entered with code while the program is running.

  • Forms
    You add these to your VB application as they are needed. They are the windows which hold the various controls (buttons, text boxes, etc.) which make up your application.

  • Code Window
    Like it's name implies, this is where you type in the code that VB executes. Notice that the heading of the window indicates with which event the code is associated.

A VB Session

When VB begins a new project, it starts with a single form which has no controls placed on it. A session in VB would go something like this:

  1. Add additional forms (if needed)
  2. Set form properties
  3. Place controls on forms
  4. Set control properties
  5. Write code for form/control event procedures
  6. Create executable (.EXE) or simply RUN program within the IDE
  7. Save project

It's important to understand that each form in VB is saved as a standalone file on your computer. The listing of all forms, and their location on your hard disk, are kept in another file which is called the project file. In VB3 the project file extension was .MAK but in VB6 it is .VBP. This file is just an ASCII text file which provides information about the VB project. There is a variety of other information which is held within the file, but all of it is directed towards describing those files (and controls) which make up the VB project. We'll talk more about the content of the file in other sections of this tutorial. As your skills improve, you'll even feel comforable about editing the project directly, using a simple text editor such as notepad. I do it occasionally when I want to make a simple change to a program without going through the VB IDE.

Even more useful is that if I want to capture a routine that I know is in a VB project, I can call up the file that has the code and copy it to the clipboard for insertion into my new project. This has the benefit of being very quick and it lets me use search tools that are not a part of the VB IDE.

Your First Application

Ok, it's already time to create you first application. Beginner's are usually shown what's called a "Hello World" application. It's called this because all the application does is display the words "Hello World" when the user presses a button. As useful applications go, it's not much, but it does show what is involved in creating an application.

  • Step 1.
    Start VB. As it VB comes up, it automatically creates a NEW application consisting of only 1 form which has no controls.
  • Step 2.
    Using the mouse, move the cursor over the toolbox and click with the left mouse on a command button control. This selects the button. Now move the cursor to the form and while pressing the left mouse button draw out a rectangular shape with the mouse. Once the shape is drawn and the left mouse is released, a command button appears on the form.
  • Step 3.
    Change the CAPTION property of the command button. Do this by clicking once on the button to select it, then pressing F4 to bring up the Property window. Scroll in the window until you find the CAPTION property. Highlight the CAPTION property and type in "PRINT". The text on the command button will be replaced by what you type.
  • Step 4.
    Remember earlier in the tutorial that we talked about writing code for events? Well, each of VB controls recognize certain events. In this example, the CLICK (left mouse press and release) is the event which corresponds to pressing the button.

    VB uses a nomenclature such as command1_click() for event procedures. Since we've not yet discussed procedures this information is a bit premature. For now, just take on faith that VB provide a place to write the code which will be executed when the button is clicked.

    To get to the location where the code will be placed, DOUBLE-CLICK on the button. A new windows, the CODE WINDOW, will appear with the cursor in place, ready for you to type the code. Type the following line of code:

    PRINT "Hello World"

  • Step 5.
    Your program is now complete and ready to run. Within the IDE you simply press F5 to run the program. Do so now.

Your application will appear as a single window in which there is a single button labeled "Print". Press the button with your mouse and you will see the words "Hello World" appear in the upper left corner of the window.

That's it! You've just written your first VB application.

To return to the IDE, click on the "X" button at the top right of the form. Later we'll discuss better ways to exit from a program.