ScriptEx.exe is a sample that demonstrates how scripting
can be done from a Visual Basic application. The sample is a spreadsheet
application for which macros can be written.
The
following files are available for download from the Microsoft Download
Center:
Scriptex.exe
(http://download.microsoft.com/download/vb50pro/samp13/1/win98/en-us/scriptex.exe)
Release Date:
SEPT-10-1998
For additional information about how to download
Microsoft Support files, click the following article number to view the article
in the Microsoft Knowledge Base:
119591
(http://support.microsoft.com/kb/119591/EN-US/
)
How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most
current virus-detection software that was available on the date that the file
was posted. The file is stored on security-enhanced servers that help to
prevent any unauthorized changes to the file.
When you run the self-extracting file, the
following files are expanded:
frmGrid.frm ' The main form
clsExcel.cls ' A wrapper class around grid
prjScrpt.vbp ' Main
project
ReadMe.txt ' ReadMe file that explains the project
How to Use This Sample
- Open prjScrpt.vbp in the Visual Basic 5.0 design
environment and run the application.
The form displays a grid in
which values can be entered. The lower-left part is a debug window, in which
individual statements can be tested. It contains a project explorer that
displays the names of modules and macros. - By default, a global module and Macro1 are created.
Double-click on Macro1 in the Treeview to edit the code.
- The edit window shows the details of Macro1. In the
Textbox, paste the following code:
Sub Macro1()
s = "This is macro1"
MsgBox s
End Sub
- Click the "Save" button to save your changes. Click the
"Run" button to execute Macro1.
- In the debug window, click on the ComboBox, and then enter
the following text:
Macro1 - Press the ENTER key to execute Macro1 and note that only
macros in the Global Module can be executed from the debug window.
- Individual lines can be executed and evaluated by using
"ExecuteStatement" and "Eval" commands. Type the following text in the debug
window and press the ENTER key.
x = 5
Now type the
following text in the debug window and press Enter.
?x
The value of x is displayed. Experiment with executing individual statements.
- Until now, all the code was written in a Global module.
Macros can also be added to user-defined modules. Right-click the
Project-Explorer and select "Add Module." Enter the module name as "MyModule."
- Right-click on MyModule in Project Explorer and select "Add
Macro." Enter the macro name as "Echo."
- Double-click "Echo." Add the following in the code window:
Sub echo(sIn)
MsgBox "Your input was " & sIn
End Sub
- Click save and then double-click on "echo" in the project
window. The TextBox displays the attributes of the subroutine.
- Select the run button. Enter some value for the input
parameter. The MessageBox displays the parameter.
- The Script control can access the host's objects by using
the "Add Object" method. In this sample, the clsExcel is exported to the script
control, and therefore, the properties of clsExcel can be accessed by the
script control. Add a new macro named "MyAdd" to your module.
- Double-click on "MyAdd" to see code window. Type the
following code:
Sub MyAdd()
' the 0 forces Integer addition
cells(1,3) = 0 + cells(1,1) + cells(1,2)
End Sub
- Click save, and then click on "View Sheet." In cell(1,1)
and cell(1,2), type a few Integer values.
- Right-click on "MyAdd." In the pop-up menu, select "run
macro." The macro will add the first 2 cells and will put the result into
cell(1,3).
For information about obtaining the Script control, please
see the following article in the Microsoft Knowledge Base:
184739
(http://support.microsoft.com/kb/184739/EN-US/
)
: INFO: Where to Obtain the Script Control