Using the ScriptControl in Your Own Programs

The hardest part about using the ScriptControl is finding the right situation in which to add it. Here, I’ll offer some suggestions of when you might want to use it.

Many business applications have rules that are unique to a particular business. Using the ScriptControl allows you to customize your application without recompiling for each business. All you need to do is to code the business-specific rules in VBScript for each organization. Then they could be loaded at runtime. A good example of this is computing sales tax for a particular state. Some items are taxable, and some are not. Even the tax rate may vary depending on the item. Using VBScript allows you to easily write a specific program for a state and quickly change it whenever the state changes its laws related to computing sales tax.

Another place where you might consider using the ScriptControl is in game playing. Many games such as SimCity and Civilization are rather complex and often involve tedious tasks that can follow a specific strategy. For instance, an advanced Civilization game player could benefit from a VBScript program that would automatically choose the next advance based on the advance just completed and the advances achieved by the other players.

Yet another place where VBScript might prove valuable is to create a batch-processing facility. Suppose you have a tool like Photoshop, where you can perform various tasks based on keyboard and/or mouse movements. Then suppose that you need to apply that same transformation ten or fifty times. Rather than doing it by hand, it might be useful to write a little VBScript program that would allow you to repeat the transformation as many times as needed. This would not only save time, but it also could reduce mistakes.

© 1998 SYBEX Inc. All rights reserved.