|
Best of Support |
|
|
Running VB or Java Script from GhostFill |
|
You can use Microsoft's "ScriptControl" object to execute a Visual Basic or a Java script from the GhostFill environment.
Issue
We had a requirement for a GhostFill application as follows:
At run time when the relevant Dialog appears, a read-only Microsoft Word document must open alongside the Dialog showing context to the information being captured. In the OnEnter event of each Dialog field, the cursor in the Word document must move to a new position (bookmark) pertaining to the context of that particular field.
Solution
The following is an extract of the script that was used in the appropriate Dialog events to create this scenario:
%[DocName = 'c:\test.doc']
%[BookMarkName = 'testBookmark']
%[ScriptControl = CreateObject('MSScriptControl.ScriptControl');]
%[ScriptControl.Language = 'JScript']
%[ScriptControl.AllowUI = true]
%[Word = ScriptControl.Eval('function GetWord() { try { return GetObject("","Word.Application") } catch(e) { return new ActiveXObject("Word.Application")}} GetWord();')]
%[DocObj = '';]
%[ForEachBlock('Doc',Word.Documents)]
%[KeepBlockIf(Doc.Name = DocName)]
%[DocObj = Doc]
%[EndBlock]
%[EndBlock]
%[KeepBlockIf(DocObj='')]
%[DocObj = Word.Documents.Open(DocName,false,true)]
%[EndBlock]
%[KeepBlockIf(DocObj.Bookmarks.Exists(BookMarkName))]
%[DocObj.Activate()]
%[BookMark = DocObj.Bookmarks(BookMarkName)]
%[BookMark.Select()]
%[Word.Visible = true]
%[DocObj.ActiveWindow.ScrollIntoView(BookMark.Range,True)]
%[EndBlock]
%[Word = ''; DocObj = ''; BookMark = '']
// Create the appropriate "VB" object
%[VB = CreateObject('MSScriptControl.ScriptControl')]
%[VB.Language = 'VBScript']
// Create an object called "GF" which points back to the GhostFill ServerList from within VB:
%[VB.AddObject("GF", Servers, false)]
// Set your script to a GF Block variable:
%[SetBlock("MyVBScript")]
A = InputBox("Enter a value (integer) for A", "", A)
B = InputBox("Enter a value (integer) for B", "", B)
C = Int(A) + Int(B)
MsgBox A &" + " &B &" = " &C
// The above will message A+B=C in a VB message box. Store the values back in to GhostFill for future use:
GF.variables.A = A
GF.variables.B = B
GF.variables.C = C
%[EndBlock]
// Execute your VB script in GhostFill:
%[VB.ExecuteStatement(MyVBScript)]
// Release the VB objects:
%[VB=""; GF=""]
// Show the values stored in the GhostFill variable list:
%[MsgBox("GhostFill Message", A &" + " &B &" = " &C)]
Ricky Burrell