The Visual Basic Environment

Welcome to the third Article in our Visual Basic section. Last week we installed Visual Basic. This week we will be looking at the environment that you are presented with when you start Visual Basic, and set a few options that will prepare Visual Basic to meet our demands.

Let’s run Visual Basic for the very first time. The first thing you will see is this screen, where you are presented with a list of various project templates.

For now, select Standard EXE, and click on Open. The next Visual Basic will add a few things for you, to accomplish the standard setup it needs for creating a Standard Executable (Which eventually will be a runnable program with a .exe extension).

The Visual Basic Interface

The screen you see now will look more or less similar to this one.

Wow. That’s a lot of weird windows. Let’s go through them one by one. In the lower-right corner, you will see the Form Layout window.

The Form Layout Window

Using the Form Layout Window, you can choose where your program will essentially show up once it is completed. As you can see, it already contains a small version of a form, which can be moved around the screen.

Right-clicking the Form Layout Window will also give you the possibility to select some positions (In the ‘Startup Position’-sub menu). The Form Layout Window is not something we will be using often. (Well, I don’t use it often. It’s up to you to decide whether or not you leave it visible, or just hide it).

The window right above the Form Layout Window is the Properties Window.

The Properties Window

This is one of the windows you will probably use a lot. It shows the properties of the currently selected object. What is a property, you ask? The definition from MSDN is: “A property is a characteristic of an object, such as size, caption, or color”.

Let’s look at this a little more in-depth, shall we? Imagine for a second we’re a God. We created a world, threw in trees, bushes, and what not; added a few animals, and are now working on tossing in a few people. Every person has a few characteristics: Eye color, hair color, a name, a shoe-size, etc. With the Properties Window, you can quickly see all the various properties on objects, and set or change current properties.

The Properties Window is made up out of three elements (As seen in the picture):
# Object Box
# Sort Tabs
# Property List

The Object box provides a list of objects currently in use in the project, of which you can set properties.

The Sort Tabs provide a quick way of sorting the Property List. You can sort either by category, or alphabetically. This is really a matter of choice, or habit. Use whichever way you prefer.

The Property List provides a list of all the properties that can be set for the currently selected object. The left column provides the property name, the right column shows the currently assigned value.

Under the Property List, a short description of the currently selected property is displayed. (You can turn this off by right-clicking the Property Window, and unchecking the Description option).

Above the Properties Window, we’ll find our good friend the Project Explorer.

The Project Explorer

The Project Explorer shows the different files that make up your project. Notice that in the above screen shot, I added a few extra files, to show a more extensive window than the one you will currently see.

On the left side of the screen, you will find the toolbox.

The Toolbox

The toolbox holds various ActiveX controls that you can use in your projects. In addition to the standard ones you already see, you can also add other controls (that could be provided by Microsoft, third-parties, or controls that you made yourself).

More on controls next week!

In the middle of the screen, you will find the Form Designer.

The Form Designer

The Form Designer shows you the interface of your application. You can use the Form Designer to determine exactly what your project is going to look like, which controls will be available, which text will be displayed where, etc, etc.

This leaves us with two more things to discuss concerning the interface. The toolbar, and the menu, both of which have a lot in common with standard Windows applications, but offer a few new functions. Let’s tackle the toolbar first.

The Toolbar

The Toolbar provides a number of icons, some of which you will undoubtedly recognize from programs as Word, or any other Windows Application.

We’ll briefly describe the various icons here, but won’t go deeper into what they do for now, as we will get working with that gradually, as we advance more and more into the actual programming process. You can get little description-labels by hovering the cursor over the icon for a second.

The first three icons are specific to Visual Basic. The left-most one allows you to add other projects to the project you’re working on, the middle icon adds files to your project, and the right-most one allows you to create user-menus.

The next few ought to look rather familiar to anyone who worked with Windows before. The first icon is for Opening a file, the second one for saving a file. The third icon is for cutting, the fourth one for copying, the fifth one for pasting, and the sixth one is for searching. The two arrows on the far right are respectively for undoing and redoing operations.

Three VB-specific icons again. They might look familiar however. They highly resemble buttons as they are used on Stereo / Video equipment. They provide the same functionality as well. The first one runs a project, the second one pauses it, and the third one aborts (or stops) the project.

These icons are all short-cuts to the various windows we discussed earlier. The first one is the Project Explorer, the second one the Properties Window, the third one represents the Form Layout Window.

The fourth one is a new one. It points to the Object Browser which we will discuss in future articles.

The fifth icon is for the Toolbox, and the sixth is a new one again. It points to the Data View Window, which we will discuss when we get to the article about Connectivity to Databases. (Which will be a few weeks from now).

The right-most icon the Visual Component Manager; basically a repository database for storing reusable bits and pieces of code, files, components, etc in.

The last part of the toolbar is for keeping track of the position and size of controls. The leftmost part is for the position, while the right part lists the size of a control. To see what both do, double-click on one of the icons on the toolbar, which will make a control be added to your form. Rezise and move the control on the form, and the numbers will change.

The Menu

The Menu contains a few default Windows menu-items (like file, edit, view, help, etc.), and a few functions specific to programming (like Debug, Run, Project, etc.).

# File-menu; provides file-related functions. (Open / Save / New / Print)
# Edit-menu; provides edit-related functions (Cut / Paste) as well as some look-up functions.
# View-menu; provides functions to access various Windows.
# Project-menu; provides ways to add files, and edit properties of the current project.
# Format-menu; provides functions to format controls on the form.
# Debug-menu; provides functionality to test your code, as well as tracking down errors.
# Run-menu; provides different ways to start and end a program.
# Query-menu; provides database-functionality. Only available in Enterprise Edition.
# Diagram-menu; provides database-functionality. Only available in Enterprise Edition.
# Tools-menu; offers some nifty tools, like wizards.
# Add-ins-menu; offers ways to integrate various external programs into VB.
# Window-menu; provides functionality to rearrange various Windows in the environment.
# Help-menu; provides… *drum roll* help.

That concludes the description of the environment. I also promised to set a few quick options to configure Visual Basic, so bear with me for another 5 minutes or so. We’ve done the hardest part; the next few minutes are peanuts. I’ll just provide the settings here. Why I choose the settings will be explained in future articles.

Configuring Visual Basic

Click on Tools, and select Options. We’re going to make sure that we reduce the number of errors we’re going to have to deal with. On the tab ‘Editor’, check the ‘Require Variable Declaration’ box.

On the ‘General’-tab, I’d recommend selecting the ‘Break on Unhandled Errors’ option. This will make debugging easier.

That’s it! Thanks for sticking with me for so long. In next week’s article, we will discuss the standard controls, and include a few of them in a project. We’ll take a look at their common properties, events, and methods, as well as make our first actual program.