Basically Visual

February/March 1997

by Peter G. Aitken 1997

Originally published in Visual Developer magazine


It’s Here! (almost)

I have been working with the beta of the new version of Visual Basic for a few months now, and I am absolutely bursting to tell you all about it. Believe me, there is lots to tell! Unfortunately I cannot. This column is scheduled to appear a few weeks before the official Visual Basic 5 product release date, and Microsoft wants the wraps kept on until then. Too bad, but after all it’s their party.

While I cannot tell you all about Visual Basic 5, I can tell you some things about it. How is this? Microsoft has publicly released the beta of a limited version of Visual Basic 5, called the Control Creation Edition (you can get it at http://www.microsoft.com/vbasic/). As the name implies, this version is limited to creating ActiveX controls and cannot create standard executable programs or any of the other project types that will be supported by the full version. Even so, many of Visual Basic 5’s new features are present, and I think that this brief preview will whet your appetite for the full release!

A New Interface

The first thing you’ll notice when you fire up the new Visual Basic is that it is sporting a shiny new multiple document interface. In other words, there is – like most Windows apps – a single main program window that contains all of the other Visual Basic windows, such as form design, code editing, and immediate. The new MDI interface is a significant change from the old Visual Basic interface, which consisted of any number of independent windows scattered here and there on the screen with whatever was behind them showing through. Despite having worked with the old interface for many years, I never grew to like it, and I am sure that I am not alone in saying "good riddance."

Within the main window, the Visual Basic interface is pretty smart. You can point at the border between any two window and drag it to a new position, and both adjoining windows will adjust accordingly. If you close a window, one or more adjacent windows will automatically grow to occupy the vacated space. These features simplify the task of getting the most out of limited screen real estate as there is never any wasted space between sub-windows.

Native Code (finally!)

Perhaps the most significant change in Visual Basic, the one that we have all been waiting for, is the ability to compile to native code. That’s right, folks, no more slow P-code and no more snotty comments from Delphi programmers who have been known, not without justification, to make unkind remarks about the relative slowness of Visual Basic programs. You still have the option to compile to P-code, but I cannot imagine why you would want to. When compiling to native code, you even have several optimization options, emphasizing program speed over file size, or vice versa. Way to go, Microsoft!

Where Did I Put That Form?

With the old Visual Basic, you could drag a form to various locations within the form design window. This location determined the screen location where the form would display when the program executed (unless you set the form’s position in code, of course). Now there’s a better way. The Form Layout window, visible at the lower right in Figure 1, displays a cartoon of a monitor with a miniature "form" on it. Drag the form to any location on the layout screen to set its initial display position.

Within the form design window, the form is not movable and is always nestled in the top left corner of the window. You can drag the bottom and right edges to change the form’s size, but it cannot be moved except within the Form Layout window.

Easier Properties

The Properties window is greatly improved. It has two tabs, one displaying the properties of the selected object in alphabetical order, the other grouping properties by functional category. Thus, properties that affect the object’s appearance are in one group, those that affect its behavior are in another group, and so on. In addition, a small pane at the bottom of the Properties Window displays a brief description of the currently selected property. You can still hit F1 to get full-blown Help on the selected property, but often the brief description is all you need.

As the Control Creation Edition makes, clear, release 5 is a major upgrade to Visual Basic. It seems that the Visual Basic team at Microsoft has been listening to users and doing their homework, and all of us Visual Basic programmers are the beneficiaries.

More on Tray Icons

A couple of issues ago I explained how your Visual Basic programs could display icons in the System Notification Tray, the area in the Windows 95 Taskbar where the time is displayed. Since that column was published I have heard from a reader, Jeff Robison, who pointed out some potential shortcomings of my approach and offered a solution.

As you may recall, mouse activity over the tray icon is passed to the hidden Picture Box control as a MouseMove event, with information about the mouse in the event procedure’s argument. Here’s the problem: the X values for the Picture Box’s MouseMove event will be as was explained in the article only if the PictureBox has its SclaeMode property set to Twips, and then only for certain screen resolutions. Apparently, Visual Basic applies a scaling factor to the mouse coordinates based on what it "believes" the mouse coordinates to be, and this is affected by scaling mode and by screen resolution.

Jeff’s solution is simple, requiring only that you set the Picture Box control’s ScaleMode property to Pixels. Visual Basic now will not apply scaling, and you can use the standard values for mouse messages:

Const WM_LBUTTONDOWN = &H201

Const WM_LBUTTONUP = &H202

Etc.

If you have been having problems getting my tray icon techniques to work properly in your project, this may be the answer you are looking for. Thanks, Jeff.

Easy Internet

I don’t need to tell any of you just how hot Internet programming is these days. If Visual Basic is your preferred development tool, where does that leave you? Will you have to abandon Visual Basic for Java or Perl? Can Visual Basic simplify Internet programming as it has many other applications areas? Thanks to Crescent Software’s Internet Toolpak, the answer to this last question is a resounding "yes."

The Internet Toolpak is a collection of 32- and 16-bit controls that provides drop-in functionality for various Internet communications protocols, specifically HTTP, NNTP, FTP, SMTP, TCP/IP and POP3. For the most part, the controls are designed to provide client capabilities with the one exception being the TCP/IP control which also lets you create server applications. All of the messy details of the specific protocols are hidden away within the controls. You specify data, such as host addresses and FTP passwords, via object properties, then carry out the desired actions by calling object methods. Data that is returned by the host is parsed internally by the control, and made available to your program in ready-to-use form.

An important feature of these tools is that they are event-driven and operate asynchronously. What does this mean? To understand, let’s look first at the less desirable technique which is called synchronous or polling operation. When a program is operating over the Internet, it often must wait for data to be received from whatever host computer it is connected to. The simplest method to achieve this is to create a program loop that repeatedly checks, or polls, to see if the data has been received. This works fine, at least as far as detecting arrival of the data is concerned, but it has the serious limitation that the program is tied up in the polling loop during the waiting period.

In contrast, asynchronous operation is not dependent on a polling loop. Once data has been requested from the remote host, the program is free to carry out other tasks. When data arrives, an event is fired and the program responds with code in the appropriate event procedure. This is a vastly superior method of doing things, and is in keeping with Visual Basic’s spirit of event driven programming. With the sole exception of the Mail control, all of the Internet Toolpak controls utilize asynchronous event detection.

The FTP control was the first component from the Toolpak that I tried out, and it remains one of my favorites. Drop an FTP control into your project and you can, with a modest amount of coding, provide your Visual Basic project with full FTP client capabilities. Saving files, retrieving files, obtaining directory listings, and other FTP actions are all at your disposal. A particularly nice touch in the FTP control is that you can bind it to two standard Visual Basic List Box controls. When the FTP control reads a directory listing or a file list from the FTP server the data is automatically placed in the corresponding List Box.

With the FTP control, creating your own custom FTP client is a simple task. Even more interesting, to my mind, is the ability to easily create FTP-aware Visual Basic programs that permit users to open and save files on remote FTP servers as easily as on their local hard disk. Another potential use is an "FTP site monitor" that alerts the user whenever the files available on a specified FTP site have changed.

The Web control also has great possibilities. This control can retrieve text or binary data from a web site, obtain information about a web page (such as the date of the most recent update), and to post text to a web site. Suggested uses for this control include retrieving stock prices for display in a spreadsheet, creating a "web crawler" for automated web searches, and posting user-entered data to a web site. This control is not meant to provide the functionality of a web browser, but rather to provide additional capabilities.

When you retrieve an HTML document with the Web control, the document text is parsed and various data is placed in bound Visual Basic ListBox and in control properties. One control property returns the text with all HTML codes stripped out, while another returns the text complete with HTML formatting tags. All of the pages hyperlinks are placed in one ListBox control, while all of the Image tags are placed in another.

The hyperlinks list that the Web control maintains opens a variety of interesting programming possibilities. You could retrieve a Web document then use the hyperlinks information to generate a table of contents with jumps to the various document locations. You could also use this information as the basis for a web search engine, crawling from page to page by means of their links, looking for information of interest.

The Mail control is actually two controls, one for POP3 and one for SMPT. For the acronym-deprived, these stand for Post Office Protocol (for receiving e-mail) and Simple Mail Transfer Protocol (for sending e-mail). You can use these controls to incorporate standard send/receive mail functions with Visual Basic applications. You can also perform more sophisticated tasks, such as sorting incoming mail, generating automatic responses, and the like.

The TCP/IP control deals with Transmission Control Protocol/Internet Protocol, the method used by computers to send and receive information over the Internet. Whenever you use the Internet, TCP/IP is at work beneath whatever higher-level protocol you are using, such as HTTP or SMPT. The TCP/IP control includes support for the UDP (User Datagram Protocol) layer of the TCP/IP protocol. This is the only control in the Toolpak that provides server services as well as client services.

I’ll have to limit myself to more concise descriptions of the other controls in this package. The MIME control provides MIME (Multipurpose Internet Mail Extensions) encoding and decoding for mail messages, and can be used in conjunction with the POP3 and SMPT controls. TheUUEncode/Decode control provides encoding and decoding of mail files according to the UUEncode/Decode standard. The NEWS control permits access to NNTP servers for retrieval and posting of news articles. The RAS control is used for dial-up (modem) access to SLIP, PPP, and RAS servers. The Telnet form provides programmatic access to the Telnet protocol.

All in all this is a well planned and comprehensive package of Internet tools for Visual Basic programming. I will not claim to have tried out every feature, but the ones I did test worked just fine. Even the documentation gets good grades. The 300+ page manual provides complete alphabetical reference information on all properties, events, and methods, as well as an introductory "how-to" chapter for each control. A set of functional demonstration programs is a help, too.

You can freely distribute applications created with the Internet Tookpak without royalties. The retail price is $199 for regular purchase and $158 for a downloaded version. Check out Crescent’s web site at www.crescent.progress.com/ for details and screen shots. You can also download a free demo version of the Internet Tookpak that is fully functional within the Visual Basic environment but does not permit creation of EXE files. If you want to "Internet-enable" your Visual Basic apps, the Crescent Internet Toolpak is a great way to do it.

More is Less

Do you remember what happened a number of years ago when Postscript-equipped Macintoshes started appearing in homes and offices? It seemed that owners of these machines were incapable of producing even the simplest document without using every font and graphical doo-dad at their disposal. Short student papers would incorporate an eye-jarring combination of half a dozen serif and sans serif fonts. Half-page memos would resemble nothing more than an explosion in a type foundry. Even simple "out to lunch" signs were unthinkable without a good dose of 140 point Olde English Medieval Brush Script font. Any sense of style and balance went out the window, and the motto of the day seemed to be "If I’ve got it, I’m going to use it."

Yes, yes, I know that I am exaggerating a bit. Even so, I see the same thing happening today with web pages. Page designers have an unprecedented array of design elements at their disposal, many of which are pretty new. You’ve got ActiveX controls and Java applets, animated GIF’s and virtual reality markups, streaming audio and frames – and yes, lots of fonts! Again, the "If I’ve got it, I’m going to use it" fever is loose. All too many web pages are stuffed full of every possible visual gizmo that it can be difficult to find the content among the fluff. Such pages take longer to download, and once you have it on-screen then what?

All the flashing and wiggling may impress some people briefly, but that’s about all. Don’t get me wrong – I am not arguing for staid, boring web documents with all the panache of a dictionary page! All of these design elements have their place, but remember that people visit your page for its content, not for a light show. Take it easy, folks, and remember that sometimes less really is more!

Are You Confused?

Quick, answer the following question: What is ActiveX? Got you stumped, I bet! I’m sure you know something about it – that it has something to do with software components, and also has some connection with the Web – but if pressed could you really explain what ActiveX is (and isn’t)? And furthermore, how does it relate, if at all, to OLE? I was pretty stumped myself until recently, when I decided to determine exactly what the story is. Here’s what I found out, and while I’m sure it’s not a final answer (these things seem to change pretty quickly) at least it’s something!

Back in the early days of Windows, Object Linking and Embedding, or OLE, was developed to permit creation of compound documents. OLE version 1 permitted end-users to create documents that consisted of, for example, text created with Microsoft Word, a spreadsheet created with Lotus 1-2-3, and a diagram created with Micrografx Designer. The goal was to create a "document-centric" model where the user would be more concerned about the content of the document and less concerned with the individual applications used to manipulate the information.

OLE 1 worked, but had significant problems (which I won’t go into). Its successor, OLE 2, was based on a set of new technologies the most important of which was the Component Object Model, or COM. COM and OLE 2 provided not only improved support for compound documents, but also the foundations for an entirely new concept of the way software is developed and how programs interact with each other. To briefly summarize a complex topic, COM provides a framework for all sorts of interactions between software, not only compound documents but also system software, libraries, etc. As a result, COM technology was soon incorporated in many areas including but not limited to the document-centric paradigm. Microsoft decided to apply the term OLE to refer to all COM technologies as a group. In this usage, OLE was a term in its own right and no longer an acronym for Object Linking and Embedding.

About a year ago, the scene was further confused by the introduction of a new term, ActiveX. Initially, ActiveX referred to things that were specifically related to the Internet and the World Wide Web. As it turned out, ActiveX developments were almost all based on COM, and hence were subsumed under the new, broad meaning of the term OLE. Gradually, however, usage shifted so that the term ActiveX was used to refer to anything that used COM technology regardless of whether it was Internet related. Part of this shift was, I am sure, driven by Microsoft’s desire to counter the huge impact of Java. Whatever the underlying motivations, we now have the situation where ActiveX refers to any of the various technologies based on COM – in other words, what used to be referred to as OLE.

And what about the term OLE? Things seem to have come full circle, and the term OLE is now used in its original, more limited sense of referring to compound document technologies. I know, all these changes make ones head hurt, but what can you do? Get out the aspirin and wait for them to change it again!