Home -> Programming -> Planning -> Visual Basic Editor

The Visual Basic Editor

Programming in Visual Basic is done with the VB editor. With a few reservations, it is a very good programming editor. It is used to design the layout of our forms and write the code our programs. This page provides an overview of the editor, its main parts and the things you need to know about it.

The editor is a complex program. It is used to manage programming projects and while it can open individual files, it is mainly used to create and manage programming projects. We will start by creating a new project. This is usually the first thing we do. To create a new project select the New Project command from the Project menu. When we do this a dialog box is opened asking us to select our project type and to name the project. The dialog box looks like this:



The project type should be Windows Application. Confirm this and select the location to which you want the project saved. Normally this will be in a VB folder in your MyDocuments folder. Now create a name for your project. You should follow the same rules for naming your project as for variables. (see naming rules here) Of special note remember and follow these two rules!

First, Never use punctuation in a program name. If you do your executable will neither load nor run and the project will be reported as corrupted.
Second, You can use spaces in your file name but they will be removed from your project name by the editor. Spaces are not allowed in identifiers!

Click OK to cause the project to be created and it should look about like this:



Now let us take a look at the various areas of the VB Editor. There are many features built into this powerful and complex program. The diagram below divides the program into 6 parts.

  1. Area 1 is the menus and toolbars. It contains the various commands of the program which we activate as we need them. Remember the shortcuts! They more we use them, the easier they are to remember, so learn the ones you use all the time.
  2. Area 2 is the toolbox. This is where all the various tools are housed. Here we select the objects we want to place on our form.
  3. Area 3 are docked windows. The two main windows are:
    • The Solutions window - it is a view of all the files which make up our project.
    • The Properties window - each time we select an object on our form it displays all the property settings for that object.
    If either of these windows are not visible, they can be turned on from the View Menu in Area 1.
  4. Area 4 is our project window. We usually start a project by building our form view. When finished building our form we switch to the code view. (We can toggle between these views by using the icons at the top of the Solutions window in Area 3)
  5. Aread 5 is the Error reporting area. In this view it is collapsed to minimize the space it occupies. When we run our program the editor first checks for syntax errors. All errors are listed here. Note! While your program can run with errors, the executable image is not updated, so any changes you have made to your program are not yet implemented.
  6. Area 6 is the feedback area of the program - often called the status area. The editor uses this area to communicate routine messages tot he user.


The editor operates in three distictly different modes. These modes are:

Other Editor Features

There are several other features that make the work of programming easier. While I will not be exhaustive here, I will mention those which give you the biggest bang for the buck.

Alignment of Controls

As mentioned on the Program Interface page a good interface will line up controls in a functional and attractive manner. Of course the hard way to do this is to line things up using the mouse. This version of VB makes that easier by having pop-up alignment markers appear on the screen when we drag one control into an alignentment with another. However there is a menu called Tools which contains a nice selection of controls to align and to space control elements on a form. Using these commands certainly speeds up form design.

Auto-Completion

This is a feature that I do not use to full advantage, but it is well worth learning and using. I have resisted using autocompletion features in programs for more than twenty years now. At the heart of the matter, I am aware that the way most people use them gives people a reason not to learn the spelling of words. However, especially for non-typists, auto-complete is a really substantial benefit. To use this feature you simpley need to press control-spacebar. To more effectively use it you need to have typed enough of the word, command, control name or variable name to have uniquely identified it. If you do that then the word is automatically completed. If you have not typed sufficient characters to uniquely identify the word then you get a pop-up list appearing on the screen to help you do so. If you want to learn to be emter your code reasonably fast then keep your hands off the mouse and on the keyboard! For example, if you are typing an assignment statement to make a Happy Face picture control visible, you would type:

picHappy.v

and then press control-spacebar. The visible property is the only one which starts with "v" so one character is enough to uniquely identify this property. For a textbox you would need to type:

txtName.te

and then press control-spacebar. There are other controls which start with "t", but "te" is unique. Some experimentation with the common properties will help you learn what to type. This feature can save you a lot of time especially if you want to follow the new convention of using suffixes to tag you controls and variables. Since these names are much longer than names using the Hungarrian notation, the auto-complete feature is even more of an advantage.

Property Completion

When typing control names with property extensions you can save yourself a lot of effort by learning the editor's conventions. Lets say we want to assign the name John Smith to the Text property of the textbox named txtName. We would type the control name as follows:

txtName

and then we type a "." (a period). As soon as we type the period, the editor should provide a pop-up list of properties owned by this control. If it does not appear, the most common cause is that we have made one of two mistakes.

Once the property list appears, type enough to get to the property you want to use and then we want to use the auto-completion features of the editor. For the Text property we would have to type te to cause the Text property to be selected. Now we need to trigger the auto-completion. There are two ways to cause the auto-completion at this point and each does something slightly different. Select which method you use according to what you want to have happen.

In this case we have entered the left side of the line of code but still want to enter the value John Smith. Since the pop-up list is already on the screen we do not need to hold the control key down. So we just press the spacebar. This gives us the following with the cursor still on the same line:

txtName.Text

Now continue typing the remainder of the line: = "John Smith" and press enter. This will produce the full assignment statement.

txtName.Text = "John Smith"

Now that might seem like a lot of work to learn all of it and remember to do it, but since we use assignment statements many times in each program we write, it is well worth the effort!

Creating Event Procedures

Visual Basic has been described as an event-driven language for many years now. This means that when the user interacts with a control, the user's action causes a specific module of code, written by the programmer, to be executed. To maintain the integrity of this process, the editoR will write certain parts of the code for us. This is described on the Event Procedure page. Do not try to write this code yourself since the editor can do it for you, and will not make any errors in doing so. This does assume that you have named your control before you trigger the creation of the Event procedure declaration. Remember we cause this to happen by double-clicking the control on the design form.