Web Developer's Journal internet.com
Back to the Web Developer's Journal Main Page
internet.com
side nav bar

Web Developer's Journal Archive Section

This article is out of date, but may still be useful to some readers.

Visual Basic 3.0 for Windows

by Kief Morris


Jobs at webdeveloper.com


If an article is here in the Archives, it is because we feel it may be out of date in one way or another. Some of the information may still be useful to some readers, but keep in mind that some information may no longer be accurate. Product capabilities change, prices change, links may no longer work, and in fact, the company that makes this product may have gone down the tubes long ago. To get the latest, we recommend that you go to The Web Developer's Journal Home Page, and see if there is a more recent article about this subject.
HOW DID THEY DO THAT???

Find out in:
Amazing HTML



Site Map



Check out our Web-based
Discussion Groups:

Check out and join our email-based Mailing Lists for Web developers.


Developer Channel
FlashKit
Jobs.webdeveloper
JavaScript.com
JavaScriptSource
JustSMIL
ScriptSearch
Streaming Media World
WebDeveloper.com
WebReference
XMLFiles
WDVL
As a C and C++ programmer who is slowly learning the art of writing Windows applications I had heard of Microsoft's Visual Basic, and dismissed it as a serious programming tool. BASIC was fine when I was in high school playing with a Commodore 64, and later playing with QBasic on a PC, but as an adult doing graduate work in computer science I have been firmly told to set aside the things of childhood and use C. But curiosity got the better of me so I tore the shrink-wrap from Microsoft Visual Basic 3.0 and installed it to see what, if anything, the language is good for.

How Visual Basic Works

In addition to the sin of using BASIC for coding, Visual Basic earns the contempt of many serious programmers for being easy to use. For cripes's sake, you draw programs as much as write code! VB programs are built around two major types of components, "forms" and "code modules". Forms are windows, whether they're simple dialog boxes or full windows with menus. You choose various controls—text boxes, list boxes, radio buttons, etc.—and place them on the form, resizing and repositioning them easily by dragging and dropping. Objects such as controls, windows, and labels have properties like color, text, and border style, which are set in the properties window. If you keep the properties window open while you work it changes, listing only those properties which apply to the currently highlighted object. Most properties are analogous to attributes which are changed in a C or C++ program by passing arguments to functions, or by filling out structures. For instance, changing the mouse pointer from an arrow to an I beam as it passes over a text box is as easy as opening a drop-down list of pointer types in the properties window for the text box. Many object properties can also be altered at runtime by code. You can write code to be executed when events relating to the object happen. In C you have to write a message loop which calls the appropriate function when an event such as a double click occurs, then write the function. In Visual Basic each form has its own code module which can be opened in a separate window. From this window you select any object on the form and an event which can happen to it, then add and edit the code to execute when the event occurs. This is a handy way to keep your code organized, although some programmers dislike having their code broken up into so many little files. It's easy to forget exactly where you put a certain piece of coding you want to reuse. In addition to the code module associated with each form, you can build common code modules with routines that can be called from any other form. This way you can write code that can be executed by a menu command, button, or double click in a list box a single time and call it from the procedures for those objects, rather than duplicating code. Menus are a snap to implement in Visual Basic. There is a Menu Design window to build the menu structures, complete with access keys, shortcut keys, and separators. The VB manual describes how to build menu control arrays to have a list of menu items that changes at runtime, such as currently open windows or the last four files loaded. Menus can be controlled at runtime with BASIC code, disabling items, adding check marks, or even hiding or addingselections. It's easy to add code to menu items to define what happens when the user chooses them.

Power at Your Fingertips

What impressed me most about Visual Basic is how easy it is to do complicated and powerful things. The sample programs in the Programmer's Guide, the starting point of the five manuals in the VB Professional box, are amazing in how simply they tap the power of Windows. In Chapter 2, "Your First Visual Basic Application", the reader is instructed to draw five controls on a form, change a couple of properties for four of the controls, and write eight lines of code. The result is an application which allows you to navigate through your drives and directories using typical Windows file dialog controls, and choose a bitmap, icon or Windows metafile, which will then be displayed. This took maybe five minutes going slowly through the instructions, and I spent half an hour playing with my new app, browsing the bitmaps and icons that come with Visual Basic. The text editor in chapter 4 takes a little longer to put together, but again the power that comes out of a small amount of work is amazing. You draw a large text box which can be used to edit a document. If the user selects text to copy to the Windows clipboard you can carry this out with a single line of code—"Clipboard.SetText = txtEdit.SelText". "Clipboard" is a predefined object which refers to the Windows clipboard, and ".SetText" means put the following text into the clipboard. "TxtEdit" is the text box control on the window, and the ".SelText" property refers to whatever text the user has highlighted by dragging the pointer over it. The only one of these four things which isn't predefined in VB is txtEdit, which you actually have to draw on a form and name yourself (a whole 10 seconds work if you're slow). Although Visual Basic 3.0 isn't quite up to the same standards of ease of use as more recent Microsoft products such as Word 6.0 and Access 2.0, it's still refreshingly useable. Like most users, I don't bother to pull out the manual every time I want to do something new with an application. Instead I just try doing it, guessing how to make it work. I then wait for a dialog box to pop up with some information that gives me a hint about the right way to do it. Visual Basic startled me many times by never popping up the dialog—it worked the way I guessed it would. When I say VB doesn't measure up to more recent Microsoft products, I'm referring to small touches of usability that I found in Access and was disappointed not to find in VB. A minor example is the ability to double-click on the sizing control of a text label and have it snap to fit the text. A major example is help labels on the button bar. The current trend in Windows applications is little yellow boxes that pop up with descriptive labels if you let the pointer rest on a button for a moment. Visual Basic 3.0 doesn't give any indication what the buttons do, so you have to use trial and error. The product also lacks the Wizards found in recent Microsoft products, except for the Setup Wizard described below.

More Power

Visual Basic gives programmers access to pretty much anything you could conceive of doing in Windows. Multiple Document Interface (MDI) applications are easy to implement. VB applications can tie into databases including Access, Paradox, Btrieve, dBase and FoxPro, which makes it ideal for custom designing front ends to large databases. DDE and OLE functionality offer considerable power for linking a VB application to other DDE or OLE enabled Windows programs. The usefulness of Visual Basic is greatly extended by the ability to call procedures in DLL's. Programmers can combine the power, efficiency and speed of whatever language they prefer with the easy user interface design of VB by writing the meat of the application into DLL files, then calling the appropriate functions from Visual Basic. This is a must for really huge projects, since Visual Basic projects have limits on the number of objects and procedures, and procedure size, among other things. Most of these limits are large enough to avoid cramping all but the very largest applications, and the documentation spells out the limitations of Visual Basic applications in detail. Visual Basic 3.0 Professional Edition ships with gobs of icons, over 450, including many which are useful for button bars. It also comes with a Setup Wizard and Setup Toolkit. The wizard, like other Microsoft wizards, consists of a series of dialog boxes which ask for information about the options you would like. It then creates master copies of distribution floppies. The toolkit gives you more flexibility than the Wizard, since you can customize the setup program the user will use to install and configure your software, and use your own compression utility.

The Docs

The Professional Edition of Visual Basic comes with five books. The Programmer's Guide is the main manual for learning to use the language, covering everything I've discussed so far. The Language Reference lists Visual Basic commands, objects, properties, methods and events, and will quickly take over from the Programmer's Guide as the book to keep handy when you get past the learning stage and into serious productivity, although most of the information is available from the on-line help. The final manual is the Microsoft Office Developer's Kit, which explains how to combine Visual Basic with Microsoft Office applications to design and program integrated solutions.

So What?

Visual Basic should be of interest to a pretty broad spectrum of programmers and would-be programmers. People new to programming will be able to get up and running pretty quickly, although I'd advise that you be pretty familiar with the way Windows works before tackling it. If you're interested in becoming a serious programmer you'd be well advised to learn a regular, procedural language before tackling VB, since the visual programming paradigm uses an entirely different way of looking at computer programs. Anybody with previous programming experience, especially with other Microsoft BASIC products such QBasic, will hit the ground running. I've worked with several languages, although not at a professional level, and was able to build the rudiments of a mail reading program that reads QWK format mail from BBS's in less than two days after installing Visual Basic. VB is especially useful to programmers who've worked with DOS or UNIX but are new to message driven GUI platforms. It's a quick way to pick up the concepts of how Windows works before learning how to write Windows apps in C or C++. Why would a serious programmer want to use Visual Basic? To get applications up and running quickly. Windows applications can be written with Visual Basic in a fraction of the time it would take in C or C++. When deciding whether to write an application in C++ or VB I would consider not only the time, but how much the application has to do besides interface oriented activities. If the app is mostly involved in reading and presenting data and getting and writing input from users Visual Basic is perfect. If user interaction is very minor—if the app will spend a lot of time processing data, for example—I'd recommend writing it in C or C++, or writing DLL's in C or C++ to be called from a VB interface.
Advertising Rates & Policies Contact Subscribe to Our Mailing List Please send us mail! Webmaster Web Developer's Journal

internet.com
e-commerce
WebDeveloper Network