Special Edition Using Visual Basic Script kkvbsfi.htm
- Special Edition Using Visual Basic Script -
Appendix D - Porting Visual Basic Applications
When VBScript first appeared on the scene, it seemed unlikely that any effort to port VB programs to VBS scripts was even remotely feasible. Even apart from language limitations (such as no file I/O, no Typed structures, no Class modules, no Collections, and so on), the overriding reality was that VBS "applications" were HTML-bound. As has oft been noted, HTML, basically an upper-left to lower-right text-flow formatter, is ill-suited in situations that vector off from its original mission.
The recent appearance of HTML Layout Page functionality, combined with the productivity-enhancing ActiveX Control Pad have changed this assessment to the degree that it is no longer unthinkable to port some VB applications to the Web.
If you are willing to do a fair amount of work dealing with the limitations and differences that remain, you will be able to bring certain VB applications to VBScript. At the very least, you should be able to duplicate most, if not all, of your user interface elements. Even so, there are some show-stoppers you need to be aware of from the start. If your program depends on any of them, you'll need to seriously consider whether you want to proceed.
Considering a Few Caveats
HTML Layout Pages, for all their similarity to VB Forms, are severely lacking in terms of properties, methods, events, and behavior. Essentially, they are dumb containers of controls; if you need to do anything at the form level (VB form, not HTML form), it won't happen, at least at this stage of the game. This includes such things as using the Print method to place text directly on a form, graphics methods (Line, Circle, and so on) to draw on a form, hiding, showing, or unloading a form, and trapping any events (such as mouse clicks or keystrokes).
You won't be able to do anything with Typed records. You may be able to get around this limitation by using multi-dimensional arrays, or, groups of arrays. You can't create Collections. Again, you may be able to use arrays this was SOP prior to VB4, so it's definitely within the realm of "doability."
Class modules don't exist in VBScript. Nor, for that matter, do standard .BAS modules. You can deal with the latter omission by placing your procedures in the same file as your controls, or the HTML file that holds points to it. (At the time this book goes to press, HTML Layout Pages must reside in .ALX files, and an <OBJECT...> reference to the .ALX file must be placed in an HTML file. Microsoft has announced that when IE 3.0 is released, it is expected to support the use of HTML Layout Pages within an .HTM page.) As to Class modules, you may be able to duplicate their functionality by using procedures. Clearly, if you have a heavy investment in Class modules that you want to port over to Web applications, it may be in your interest to wait a while. See "Sweeping the Horizon," in this appendix for what may be a glimmer of hope.
Other features that you're "protected" from include the Printer Object, communications ports, and API (or other .DLL) calls.
File I/O is a real problem. You can write Class wrappers in VB4, and compile them to in-process .DLLs (for information on this topic, check out Que's "Special Edition Using VB4"), but, you should realize that it's an exercise that's not for the faint of heart. In addition to heavy VB coding, you'll need to embed <OBJECT> tags at the HTML level, using ClassID references, and at this time, it's impossible to use them with HTML Layout Pages, as the ActiveX Control Pad won't work with anything that doesn't meet the new ActiveX qualifications.
If you get that far, you'll still be faced with a security issue. The creators of the Internet Explorer have not simply relied on VBScript's lack of native file I/O for protection from malicious programmers. Attempting to use an object that does not contain a valid digital signature from a certificate agency, will result in warning boxes being displayed each time the page is loaded, unless security in the Internet Explorer is shut down. Shutting down security is definitely not recommended unless you are absolutely certain that the browsers in question will never wander off the safety of a corporate Intranet.
Sweeping the Horizon
If you do require language and/or object functionality that is not available in VBScript, you should remember that VBScript, VB, Internet Explorer, Windows, and even the Internet, are all moving targets. The only time something stands still is when it's dead in the water. It's not unreasonable to hope that later versions of the platform will include functionality that is missing now. Right now, VBScript is in its first generation. Windows is poised to undergo a major transformation, as the desktop blends into the Internet. No one outside the inner sanctums at Microsoft can say exactly where things will end up, although we do know that in general, we'll be getting better tools, more robust language implementations, and easier means for accomplishing tasks.
Microsoft has been dropping teasers in the press regarding the next major release of Visual Basic. Some of what they've publicly made known has a direct bearing on the things you'll be doing with VBScript and HTML Layout Pages.
For instance, you'll be able to write your own ActiveX controls, and roll in whatever functionality you require. Because Visual Basic is a full-featured language, this means that you should be able to supply much of the functionality that is currently missing from VBScript.
In the majority of cases, if you have a VB application that you want to port to VBS, you'll be looking at a complete rewrite. You should, however, be able to preserve the "look and feel" of your applications, assuming you can avoid use of graphics methods and form events. Many specific procedures, and much of your existing event code routines, can be carried over to VBScript, in some cases with little or no change. However, the structural aspects of your code Modules, Classes, and data structures will need to be redesigned, or rewritten.
If, after you assess the situation, you realize that the law of diminishing returns has been invoked, you'll need to make the hard choice to either scrap the project, or come up with a workable alternative. No amount of advice or counsel can protect you from situations like this, and although they test your mettle, they can also provide opportunity. Take the resources at hand, reason out the situation, and present a solution. That's what sets you apart from the pack.