Quick Tutorial to 64-bit Tablacus Scripting Control


Tablacus Scripting Control is the 64-bit Alternative of msscript.ocx. Microsoft does not have and will not plan to make a 64-bit Script Control. The Script Control is a very powerful and easy to use tool when you want to do some scripting in your application. This tutorial will guide you with the basis of the 64-bit Tablacus Scripting Control.

Scripting Control allows users to run some scripts on the fly without re-compiling your application.

Installation & Uninstallation

You can git clone the source code and compile to tsc64.dll using Visual Studio 2015/2017 compiler. Also, you can directly download the pre-compiled binaries.

tsc64 Quick Tutorial to 64-bit Tablacus Scripting Control tutorial vbscript

tsc64.dll

The essence of the Tablacus Scripting Control is the tsc64.dll which you need to register as a COM library. You can throw that file into the %WINDIR%\System32 (optional) and run the following command using administrator privileges.

regsvr32 tsc64.dll

On successful registration, it will show the following message indicating tsc64.dll has been installed successfully.

regsvr32 Quick Tutorial to 64-bit Tablacus Scripting Control tutorial vbscript

regsvr32

To remove the script control, you just need to add /u parameter for example:

regsvr32 /u tsc64.dll

How to Use?

For 32-bit Microsoft Script Control, you create a Scripting Object like this:

// JScript
var Obj = new ActiveXObject("MSScriptControl.ScriptControl");
// VBScript
Set Obj = CreateObject("MSScriptControl.ScriptControl")

In 64-bit Tablacus Scripting Control, you need to replace with the following:

// JScript
var Obj = new ActiveXObject("ScriptControl");
// VBScript
Set Obj = CreateObject("ScriptControl")

Setting Language

After creation of the Script Control object, you need to set its language (by default, the Language property is empty), if you don’t do this, you probably will run into the following error:

The operation could not be completed because the script engine has not been initialized to a valid language.
You can set to VBScript via sc.Language=”VBScript” or sc.Language=”VBS” or JScript via sc.Language = ‘JScript’ or sc.Language = ‘Javascript’. JScript is the Microsoft Implementation of JavaScript.

AddCode

You then can Add Some code on the fly, for example,

Set Obj = CreateObject("ScriptControl")
Obj.Language = "VBScript"
Obj.AddCode "x = 100"
Obj.AddCode "Msgbox x"

This will print value of variable x which is 100. The AddCode will be executed sequentially. However, the variables defined will be scoped locally so you can’t get the variable x via Msgbox x outside, for example.

AddObject

You can pass the object into the script control. This is quite useful as you can pass the UI Object into the script control and the UI can be scripted easily.

Set Obj = CreateObject("ScriptControl")
Obj.Language = "VBScript"
Obj.AddObject "Obj", Obj
Obj.AddCode "Msgbox Obj.Language"

In the above example, the ScriptControl Obj is passed into the script control so you can run code with this object on the fly.

Eval

Eval is to evaluate some expression, for example,

Msgbox Obj.Eval("1+2+3")

will output 6. and the assignment symbol will be treated as comparison instead of ‘assignment’. The following output False instead of setting x to 2.

Obj.AddCode("x=1")
MsgBox Obj.Eval("x=2")

ExecuteStatement

Similar to AddCode, ExecuteStatement will be useful to execute a single statement. For example:

Obj.AddObject "Obj", Obj
Obj.ExecuteStatement "Msgbox Obj.Language"

Reset

Reset is useful to clean the Script Control and make a fresh start e.g. clearing the errors and variables. For example:

Obj.AddCode("x=1")
Obj.Reset  ' After Reset, x is deleted.
MsgBox Obj.Eval("x=1")

Conclusion

Scripting Control is fun. Tablacus Scripting Control is 64-bit which allows you to add scripting feature e.g. Macros to your application without re-compiling the application.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
851 words
Last Post: PHP Function to Get Exchange Rate Between Cryptocurrency (BTC, LTC, ETH) to Fiat Currency?
Next Post: Unit Test Methods should support float numbers comparisons with EPSILON

The Permanent URL is: Quick Tutorial to 64-bit Tablacus Scripting Control

2 Comments

  1. Acton Ellis

Leave a Reply