Microsoft KB Archive/189484

= SAMPLE: SCRIPTEX.EXE Uses the ScriptControl with Visual Basic =

Article ID: 189484

Article Last Modified on 8/9/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q189484



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 INFORMATION
The following files are available for download from the Microsoft Download Center:

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 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.</li> 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."</li> Right-click on MyModule in Project Explorer and select "Add Macro." Enter the macro name as "Echo."</li>  Double-click "Echo." Add the following in the code window: Sub echo(sIn) MsgBox "Your input was " & sIn End Sub

</li> Click save and then double-click on "echo" in the project window. The TextBox displays the attributes of the subroutine.</li> Select the run button. Enter some value for the input parameter. The MessageBox displays the parameter.</li> 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.</li>  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

</li> Click save, and then click on "View Sheet." In cell(1,1) and cell(1,2), type a few Integer values.</li> 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).</li></ol>

<div class="references_section">