I really consider the MSScript Demo program I talked about at the beginning of this chapter as a throwaway program because it isn’t intended to perform a useful function other than testing. Including a new feature like a ScriptControl into an existing application can be confusing when problems arise. The most powerful feature of Visual Basic is its ability to add small amounts of code to your program and see how it works immediately.
When I wrote the MSScript Demo program, I didn’t just type in all of the code and press F5. If you take a close look at the names of the command buttons, you can see how this program evolved as I experimented with the features. Originally, the Command1 command button performed both the AddCode and the Run functions in the same routine. I added the Command2 and Command3 buttons to allow me to load and save my scripts (I didn’t show this in the text, so check the CD-ROM for the full program) because I got tired of retyping my scripts each time the program died.
The Command4 and Command5 buttons showed up because I wanted to try the ExecuteStatement and Eval methods. About this time, I added the Error event to provide a little diagnostic information about why the script failed. The Command6 and Command7 buttons were added when I wanted to test the AddCode method separately from the Run method. Specifically, I wanted to create global variables to see how they worked with the Eval and ExecuteStatement methods. Finally, I added the Exit button (Command8) because I had an empty space on the form and couldn’t think of anything better to add. I highly recommend using the technique of adding a section of code at a time whenever you need to try something new and don’t have a good feel for how it works.
The Calculator program would need a lot of work before I would let non-programmer types use it. Little things like being able to specify a filename to load or save and simplifying the file format that I use to save the VBScript code need to be revisited and changed. I might even change the routine so that it worked more like a Visual Basic event, where I passed the caption of the button that was pressed rather than associating a different subroutine with each key. I could also use a Load event to initialize the calculator, add methods that could be used to change the layout of the existing buttons, and even create new buttons on the fly.
The Charter program has been enhanced many times in this book. It shows the kind of program that is easy to build if you use the right tools. The three major controls I use in this program—MSScript, MSChart, and MSFlexGrid—represent over 2.5MB of code that I didn’t have to write. With these controls, it’s no wonder why it is easy and fast to develop complex projects in Visual Basic!