Visual Basic
Encounter

by Fred Thorlin

Speed Thrills!

Visual Basic Version 5 is terrific! I was disheartened by VB4. I found it buggy, even sloppy.

My column production dropped off to near zero. For my professional work I stayed with VB3. But VB5 has rekindled my enthusiasm. VB5 has a multitude of new and esoteric features. Probably the hottest ones are:

It is easy to get lost in the wealth of goodies. I will leave it to others, and later columns, to tell you about them. The two things I will address here are fundamental to the effectiveness of programming effort: the development environment and the speed of the code.

VB5 offers the option of producing programs compiled to machine code as well as compiling to p-code as in earlier versions. In one presentation I saw, Microsoft Product Managers showed a benchmark where VB5's generated code was faster than the code a recent Microsoft C compiler produced. To sort through the hype I wrote a bubble sort program. It took 6 minutes and forty-two seconds to sort 10,000 random real numbers on my computer. I compiled the same program to machine code, created a simple menu selection, and the time dropped to about 46 seconds. This is a speed improvement of 8.7 times! Microsoft also claims a 20% reduction in the amount of time it takes to load forms. This probably is true although my measurements form loading speed are only subjective to date. The faster form loads is enough to justify moving programs to VB5. The speed of the machine code option will motivate you to attack a new range of applications with VB. Games anyone?

To activate the compile to machine code feature, select File/Make/Options/Compile. Selecting Compile to Native Code enables a raft of additional options. You have to choose between compiling for size or speed. If you check Create Symbolic Debug Info you can use the integrated debugging environment of the Microsoft Visual Studio, which supports most of Microsoft's other languages. Another frame of optimization options is accessed through the Advanced Optimizations button. It is made clear that you use these optimizations at your own risk.

It is easier to talk about speed improvement than environmental changes, but in practice I think you will enjoy the environment more. There is a bad part here, but the badness is ephemeral. The environment is different. It is as different from VB4 as VB4's is from VB3's. This is probably related to the fact that VB5 was well into development before VB4 was released. They may have even started development at about the same time. The default is an MDI environment under which I have lost forms. Drove me nuts. You can change from the default MDI environment to the familiar single document interface by choosing Tools_ Options_ Advanced and checking the SDI Development Environment box. While you are down there go to the Editor Format tab and change the normal text font to Comic Sans MS. I found the default Courier made it too difficult to differentiate between "1" and "i". A sensual option is accessed through View_ Toolbars_ Customize_ Options_ Menu Animations. Your choices are really between Unfold and Slide. With either of these the VB menus sort of slip onto the screen instead of snapping onto it. It looks slick. If you can't choose between the two effects there is a random option which goes back and forth between them. That is where I am.

Some new tools facilitate the form layout task. A tear-off menu supports alignment, sizing and Zordering of controls. The same menu has a lock to protect your controls' positions from inadvertent movement. With the lock on you can still move them but you have to use the Control key and the arrow keys.

This coding environment is fun! As you enter statements lists will materialize. Type in a control name and a dot and a list of available properties, methods and events appears. Keep typing and the list will automatically reposition the list. When the list gets to your choice hit the Tab key and your entry will be completed. If you are referencing a container control, the names of the contained controls are included.

Enter a Dim statement and the list of available data types appears. Enter a function and the argument syntax appears. For the memory impaired it is paradise! The list even includes procedures you wrote! Another feature of note is bookmarks. You can set them on lines of code throughout your program, They look like rounded blue rectangles. You then move from one to the next with the click of a button. This is sure to save time and headaches.

Debugging has always been a strong point in Visual Basic systems. But the new stuff is terrific. The Breakpoints are more garish and easier to set. Just click in the left margin. In addition to the red highlight there is a red dot in the margin and the current statement is highlighted in yellow; you won't have any trouble figuring out where you are. While you are at a breakpoint move the cursor over a variable. The value appears in a balloon! This even works with subscripted variables! No more copying and pasting variable names into the Debug window to find out what they are.

The only downside to Visual Basic, Version 5 is that it only supports 32-bit development. If you or your shop use Visual Basic but haven't made the move to Windows NT or Windows 95, the new capabilities provide sufficient justification. I advise you to move to Visual Basic, Version 5 as soon as possible.

Fred Thorlin, a HAL-PC member, is president of Personal Instruments, Inc. a Houston, Texas based company doing Visual Basic development, consulting and training.


E-mail me at webmaster@hal-pc.org with any comments you have and tell me what you want to see here.

Back to the Magazine Home Page