ScriptEx.exe Uses the ScriptControl with Visual Basic
ID: Q189484
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
SUMMARY
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.
MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center. Click the file names below to download the files:
Scriptex.exe Release Date: SEPT-10-1998
For more information about how to download files from the Microsoft Download
Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.
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).
REFERENCES
For information about obtaining the Script control, please see the
following article in the Microsoft Knowledge Base:
Q184739
: FILE: Where to Obtain the Script Control
Additional query words:
kbDSupport kbDSD codeobject kbsample procedures scriptcontrol AddCode kbVBp
kbVBp500 kbCtrl
Keywords : kbfile kbGrpVB
Version : WINDOWS:5.0
Platform : WINDOWS
Issue type :
|