Visual Basic 3.0. (Programming Power) (Column)
by Tom Canpbell
Only Paradox offers similarly elegant and simple database handling in its language, but ObjectPAL ain't BASIC.
I had planned to discuss Windows Help files this month, but the unexpected appearance of Visual Basic on my door-step last Friday changed my whole weekend--and this month's column.
Microsoft hasn't given us Visual Basic programmers callbacks yet. What it has given us is database programming integrated neatly into the language itself, so easy to use that it constitutes a programming revolution. What with the ridiculously simple serial communications and graphics support in the Pro edition, the new database-handling features give Visual Basic an unparalleled bang for the buck. A heck of a lot of fun, too.
It's been widely reported that Visual Basic 3.0 has the database manipulation engine from Microsoft Access built in What the press hasn't figured out yet is that the result is in many ways better than Access itself! At the core of Visual Basic 3.0 is the data control. Pluck it from the Visual Basic toolbox and drop it on your form, and it appears, innocently enough, as a set of four VCR-style buttons. Press F4 to bring up the data control's properly list and set the DatabaseName property to the name of a database file (it can be from Access, Paradox 3 or 3.5, dBase III+ or IV, or Btrieve). You now have a list of the tables and field in the database at your disposal without having to type or remember whether the field was called last or Last Name. (An Access or Btrieve file can contain more than one table--what most phan people call a database--but the one table per file.) Choose the table yopu want in the RecordSource property just by paging through it with the arrow keys. In a new application, this control will be the first one, and it will be given the default name Data 1.
Now, for each field you want on the form, use a text box control. It has a new property called DataSource, which you'll set to the name of the table, and a DataField property, which you'll set to the name of the field you want it to display.
Finally, you might wish to add a few command buttons. Double-click on one and give its Click on one and give its Click procedure this line of code.
Data 1. Recordset.AddNew
This will be the New button to add records, so give it the caption New. Another button will contain this code for its Click procedure.
Data 1. Recordset.Delete Data 1. Recordset.MoveNext
You now have a working database manager that will let you add and remove records with all the Windows trimmings of mousing, font control, and WYSIWYG printing. Oh, and you can give away as many copies of the program as you wish. Suddenly the cost threshold for a developer to create and distribute robust, easy-to-use Windows database applications has dropped from about $1,000 to a couple of hundred. The visual Basic Professional edition lists for several hundred more and is well worth the money, but the Standard edition is an unbeatable value. If you're an old database hack or plan to make a living off creating Visual Basic 3.0 database applications, go for the Pro, but if you're working with a tight budget , the Standard will do fine.
What's extraordinary is that it's actually easier to create a simple database application in Visual Basic than in Access. The generic button code you just saw., for example, doesn't work in Access, which needs a frightening agglomeration of intricate Access Basic statements and Windows API calls to do the same thing. And Access won't let you attach code directly to a button the way Visual Basic has always done. You must first create a macro and then attach that macro to a button. In some ways the macro approach is more flexible; Access even stores its macros in standard Access database files so they're easier to share among applications. In all, though. I'm more comfortable with the Visual Basic direct manipulation approach. It's more natural to think of an object having code attached to it than to think of going through an intermediary such as a macro. Visual Basic 3.0 also handles some of the common "error" conditions automatically that Access doesn't. It won't bother you when you click the next record button at the end of the database (excuse me--table), whereas Access treats that as an error and puts up a message offering to halt the macro attached to that button.
That's not nearly all, of course. The language now has support for database manipulation, and it doesn't stint anywhere. The manuals, borrowed from the already superb Access documentation, are chock-full of realistic examples that leave nothing to chance. Only Paradox offers similarly elegant and simple database handling in its language, but ObjectPAL, the Paradox language, ain't BASIC.
If you're a Visual Basic programmer who missed out on the $89 Access deal last year, don't feel left out. Fill out your 3.0 update card and send it in right now.