mrScriptBasic FAQs and troubleshooting
Why do I get the following error when I attempt to access an object's property?
The 'object-type' type does not support the 'property-name' method
and a function of the same name does not exist
Check that you have specified the property parameters correctly. You specify parameters for object properties in mrScriptBasic using [ ] (brackets) and not () (parentheses) as in VBScript. When specifying more than one parameter in mrScriptBasic, you enclose each parameter in separate brackets rather than separating them with a comma as in VBScript. For example, the Text property of the MDM Label object has two parameters, user context and language. You would specify the parameters in mrScriptBasic as follows:
myText = myObject.Labels["Label"].Text["Question"]["ENU"]
I am trying to include some Word automation in my mrScriptBasic code. However, I do not seem to be able to get the code to work when I specify method parameters. For example, here is the Word VBA that is created when I record the Convert Text to Table command in a Macro:
Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=3, _
NumRows:=1, Format:=wdTableFormatNone, ApplyBorders:=True, ApplyShading:= _
True, ApplyFont:=True, ApplyColor:=True, ApplyHeadingRows:=True, _
ApplyLastRow:=False, ApplyFirstColumn:=True, ApplyLastColumn:=False, _
AutoFit:=True, AutoFitBehavior:=wdAutoFitFixed
I get a mrScriptBasic syntax error if I simply use these parameters enclosed in parentheses. The only thing I can get to work in mrScriptBasic is calling the method without specifying any parameters, like this:
myWordDocument.ActiveWindow.Selection.ConvertToTable()
Like VBScript, mrScriptBasic does not support named parameters. Therefore, you will need to call the function with the arguments in the correct order. In addition, you can use enumeration constants only when the COM component’s type library is registered with the mrScriptBasic engine, and this is not true in this case. Therefore you must find the values for the enumeration constants.
You can find out the order of the parameters and the values for the enumerations using the Visual Basic Object Browser after adding the relevant type library to the project's references. You do this by choosing References from the Visual Basic Project menu and then scrolling through the list of type libraries and selecting the ones you want; in this case, Microsoft Word 9.0 Object Library.
If you then open the Object Browser (by pressing F2), you can see that the ConvertToTable method is defined as:
Function ConvertToTable([Separator As None], [NumRows As None],
[NumColumns As None], [InitialColumnWidth As None], [Format As None],
[ApplyBorders As None], [ApplyShading As None], [ApplyFont As None],
[ApplyColor As None], [ApplyHeadingRows As None],
[ApplyLastRow As None], [ApplyFirstColumn As None],
[ApplyLastColumn As None], [AutoFit As None],
[AutoFitBehavior As None],
[DefaultTableBehavior As None]) As Table
The enumerations are defined as:
wdSeparateByTabs=1
wdTableFormatNone=0
wdAutoFitFixed=0
However, generally, the methods have sensible defaults and so the following should give the desired results:
myWordDocument.ActiveWindow.Selection.ConvertToTable(1)
I get the error “Method call failed: Unknown error 0x800A0005” when my mrScriptBasic code attempts to write Japanese characters to a text file.
If you are not working in a Japanese locale, you must specify that the text file to which you are writing uses Unicode encoding. If you are creating the text file using the File System Object CreateTextFile method, you specify Unicode encoding by setting the third parameter to True, for example:
Dim fso, txtfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.CreateTextFile("JapaneseLabels.txt", True, True)
You must also make sure that the text file uses a font that supports Japanese characters, such as MS Mincho. You can change to a suitable font when you open the text file.
For an example, see the
JapaneseLabels.mrs sample file. For more information, see
Sample mrScriptBasic files.
How do I include a double quotation mark in a single-line string literal?
By inserting two double quotation marks. For example:
sName = "Jonathan ""Jon"" Davidson"
How do I test if an object reference is no longer assigned to a variable?
Always use the
IsNullObject function. For example:
If MyObject.IsNullObject() Then
' No object reference exists
...
End If
The = Null or Is Null tests should not be used, as they can return True when the default property of a non-Null object is Null.
Is it possible to use the Logging component in an .mrs file?
You can use the CreateObject to create an instance of the Logger object. For more information, see
Using the Logging component in mrScriptBasic.
Is it possible for a script to start an external program and wait for it to finish before continuing?
Use the WshShell object that is part of the Microsoft Windows Script Host object model to accomplish this. The Windows Script Host object model provides a way of performing many administrative tasks, including running programs and outputting messages to the screen.
Here is an example of using the WshShell object's Run method three times. The first time it opens a command prompt, changes the path to C:\, and then executes the DIR command; the second time, it opens a text file in NotePad; and the third time, it opens another text file in NotePad.
When the method is called the second and third time, the third parameter is set to True. This defines that the execution of the script is to halt until the program finishes.
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.run("cmd /K CD C:\ & Dir")
WshShell.Run("NotePad.exe C:\Samples\MyFirstFile.txt", , True)
WshShell.Run("NotePad.exe C:\Samples\MySecondFile.txt", , True)
For more information about the Windows Script Host, see:
See also