Host Automation Object Samples
The following script is designed to be used with BlueZone Web-to-Host running in the Embedded Client Mode. This script will launch an "embedded" BlueZone IBM 3270 Mainframe Display session from an Object Tag. Five buttons will appear at the top of the web page. Once the session is launched, you can use the buttons to perform several functions:
Log On - Logs onto a TSO session and brings up the ISPF Menu
Perform GetCursor - Pops up a Message Box with the current Row and Column of the cursor
Perform ReadScreen - Pops up a Message Box with some text that is read from the screen
Log Off - Logs off the session
Disconnect - Disconnects the BlueZone Host Automation Object
If you have an IBM 3270 Mainframe and you want to use the script as is, you will have to change the HostAddress value and possibly the Port value located in the Object Tag.
Also, you will have to change the Username and Password located in the logOn() function with your own valid Username and Password.
The sample also contains the "ScriptOnInitComplere" PARAM shown here:
<PARAM NAME="ScriptLanguage" VALUE="JavaScript">
<PARAM NAME="ScriptOnInitComplete"
VALUE="hostConn()">
The purpose of this PARAM is to delay the execution of your script until the BlueZone Web-to-Host Control Module and associated files are completely downloaded. To use it, create a Function that launches your script. Place that Function name in the PARAM VALUE as shown in the above example and in the sample script below.
To use the script, create a text document, name it anything you wish, and save it with a file extension of .htm or .html. Copy and paste the HTML code into the document you just created. Or, you can cut and paste the script into an existing HTML page. Either way, since this page contains the Object Tag, this page will take the place of your current Object Tag page.
NOTE In
order to use this sample HTML page and script, you must have BlueZone
Web-to-Host installed and running on a web server with the optional BlueZone
scripting cab file made available to the End Users.
SEE “How
to Include BlueZone Scripting Components” located in the BlueZone Web-to-Host
Administrator’s Guide in the “How To Guide – Scripting Related” section,
for more information.
Also, In order for the BlueZone Host Automation Object to communicate with a BlueZone Display emulation session, you must enable BlueZone's DDE interface.
SEE Configuring
BlueZone to Work with the Host Automation Object
NOTE If
you want the script to automatically Log On to the host, un-comment the
last two lines of the hostConn() function. The
last two lines contain the words "else" and "logOn()".
By un-commenting
these two lines, the function "hostConn() will automatically call
the function logOn().
Some scripting languages such as JScript and JavaScript only support passing variable parameters to functions as Values (copies), as opposed to passing variable parameters to functions as References (pointers). In these scripting environments, parameters passed to functions that return data need to be of type "Object". The BlueZone Host Automation Object has built-in support for passing variables of type Object to its methods that return data, and uses the reserved object members "Str" and "Num" to "fill-in" the data to be returned. In the following Sample HTML Page, there are examples of the ReadScreen and Get Cursor Methods using correct JavaScript syntax.. The ReadScreen Method returns a string of text so "Str" has to be used, and the GetCursor Method returns a number value so "Num" has to be used.
In the BlueZone Object Methods Listing, the examples are given mostly in VBScript. However, when the syntax required by JavaScript is different than VBScript, the example is given in both VBScript and JavaScript.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>JavaScript Sample Page</TITLE>
<SCRIPT language="JavaScript" type="text/javascript">
// create function hostConn() which is called by "ScriptOnInitComplete" in the Object Tag
function hostConn() {
// instantiate the BlueZone Object
host = new ActiveXObject( "BZWhll.WhllObj" );
ResultCode = host.Connect( "A" );
if ( ResultCode != 0 )
//display an error message if can't connect
host.MsgBox( "Error connecting to session A!", 48 );
}
// log on to the host
function logOn() {
host.SendKey( "TSO" );
host.SendKey( "@E" );
host.Wait( 1 );
host.WaitReady( 10, 1 );
host.SendKey( "username" );
host.SendKey( "@E" );
host.WaitReady( 10, 1 );
host.SendKey( "password" );
host.SendKey( "@E" );
host.WaitReady( 10, 1 );
host.SendKey( "@E" );
host.WaitReady( 10, 2 );
host.SendKey( "@E" );
host.WaitReady( 10, 1 );
host.Focus();
}
// *** GetCursor Example ***
function getCursor() {
var Row = new Object();
var Col = new Object();
host.GetCursor( Row, Col );
alert( "The Row = " + Row.Num + ", the Column = " + Col.Num );
host.Focus();
}
// *** ReadScreen Example ***
function readScreen() {
var Buf = new Object();
host.ReadScreen (Buf, 8, 6, 19);
alert( "The contents of Buf = " + Buf.Str );
host.Focus();
}
// sign off from host
function logOff() {
host.SendKey( "@3" );
host.WaitReady( 10, 1 );
host.SendKey( "logoff@E" );
host.WaitReady( 10, 1 );
host.focus();
host.CloseSession (0, 1);
host.Focus();
}
// disconnect the BlueZone Object
function disconnObj() {
alert ( "BZHAO Disconnected!" );
host.disconnect();
}
</SCRIPT>
</HEAD>
<BODY>
<DIV Style="Position:Absolute;Left:10px;Top:50px">
<OBJECT ID="Seagull Web-to-host Control Module v4"
CLASSID="clsid:037790A6-1576-11D6-903D-00105AABADD3"
CODEBASE="../controls/sglw2hcm.ocx#Version=-1,-1,-1,-1"
HEIGHT=480
WIDTH=740
>
<PARAM NAME="IniFile" VALUE="default.ini">
<PARAM NAME="Sessions" VALUE="MD_S1">
<PARAM NAME="DistFile" VALUE="default.dst">
<PARAM NAME="MD_S1" VALUE="mainframe.zmd">
<PARAM NAME="MD_S1_Save" VALUE="Yes">
<PARAM NAME="ScriptLanguage" VALUE="JavaScript">
<PARAM NAME="ScriptOnInitComplete" VALUE="hostConn()">
<PARAM NAME="MD_S1_RunInBrowser" VALUE="Position">
</OBJECT>
</DIV>
<FORM>
<INPUT NAME="submit" TYPE=Button VALUE="Log On" onClick="logOn()">
<INPUT NAME="submit" TYPE=Button VALUE="Perform GetCursor" onClick="getCursor()">
<INPUT NAME="submit" TYPE=Button VALUE="Perform ReadScreen" onClick="readScreen()">
<INPUT NAME="submit" TYPE=Button VALUE="Log Off" onClick="logOff()">
<INPUT NAME="submit" TYPE=Button VALUE="Disconnect" onClick="disconnObj()">
</FORM>
</SCRIPT>
</BODY>
</HTML>