Vb Classic Survival Guide

This is an attempt to write down an assorted collection of mental notes I gathered while developing a VB application for 1 year using VisualBasic 5.0 SP3 [IE: VbClassic]. I'll try to list every pitfall I found, and some advice on how to prevent them.

 Dim v as variant
 Dim d as double

v = ".3" d = v Msgbox "v = " & v & " d = " & d

v = "0.3" d = v Msgbox "v = " & v & " d = " & d

-- JoaoLuisSilva




Criminy! With all that trouble unrelated to the actual language, I'd suggest shortening this page to Learn to program on a UNIX system



Helpful Comment there. The problems described here are specific to VbClassic but in general all frameworks have issues and quirks that need to be dealt with. When you throw in custom components written by other individuals then you have a merry mess.

Visual Basic is one of the fastest ways to create a Windows program. But like any tools you have to know when and where to use it. Visual Basic can be used to create full featured applications and you will save a lot of time using it, if you use good software development practice.

However the reason that you save time is that a lot of the nuts and bolts are in a layer beneath the VB program. (ActiveX libraries, controls, VB runtime, etc). So you have to be prepared to deal with the issues and/or bugs of that layer.

I recommend getting both Design Patterns, Refactoring by Fowler, and download one of the unit testing frameworks for VB6. Although Visual Basic doesn't support inheritance, most of the Design Patterns deal with interfaces which is supported by Visual Basic. Design Patterns will help you with the overall structure of the program, and refactoring will help you changes the program when you find that you have the design wrong or need to extend. The unit testing allow you to quickly pinpoint problems with any change you make.

My top suggestions for designing software with VbClassic

1) Learn how to and write call windows DLLs from VbClassic. This will require learning C/C++ or another language. This will greatly expand your choices for solutions.

2) Separate the User Interface from the Data Structures by using ActiveX DLLs.

3) In the User Interface separate the Forms from the Commands. Use the Command Pattern from Design Patterns. Again use Active X DLLs. Ideally the only thing that should be in your EXE project are the forms.

4) Don't blow off unit testing. If you use the command pattern to encapsulate actions you will find that unit testing becomes much easier.

5) You should design your VB ActiveX DLLs so that the number of files you need to update for specific types of changes or bug fixes is minimized. For example if you want to add or change a report a good design will require that only DLL be changed.

6) For features that are continually being updated consider making an interface, and use the Factory pattern to isolate those features from the rest of the software. For example have all reports in their own DLL, and have them all implement IReport. When the software starts have a factory class in that DLL return a collection of IReport. Typically the two areas that need this are reports, database connections, and files import/export.

7) Test for extreme cases where object parameters are passed nothing, collections with 0 items, collections with extermely large items.

8) Never have double link child to parent, parent to child. If a child needs to know its parent use the proxy pattern instead. VbClassicObjectProxy

I go into detail because double linked pairs of Object are such an evil for large applications in VB. Similar the evil of null pointers in C/C++. The garbage collector of VB can't get rid of double-linked objects, so memory will be chewed up eventually causing much weirdness and grief.

9) Find a copy of Hardcore Visual Basic by McKinney?. He will take you under the hood of VB.

10) FileSystemObject? in the MS ActiveX Scripting DLL is a much saner way of dealing with files. In addition, the PropertyBag? Object can take any object and turn it into an array of bytes. You can save and reload this array and recreate the object.


CategoryVbClassic


EditText of this page (last edited January 31, 2009) or FindPage with title or text search