Appendix - Host Automation Object


Sample Scripts

The following Sample Scripts are provided to aid you in the development of BlueZone scripts using the BlueZone Host Automation Object.

Sample Visual Basic Script

Sample HTML Page with VBScript

Sample HTML Page with JavaScript


Sample Visual Basic Script

This script is designed to be used with BlueZone for the Desktop.  The script will launch an already existing BlueZone iSeries (AS/400) session (S1), logon to the host (using the S1 configuration settings from the Windows Registry), navigate to the user’s Job Log, and write the contents of the Job Log to a file and store it in the following location:

C:\JOBLOG.TXT

 

To modify and use the script, create a text document, name it anything you wish, and save it with a .vbs file extension.  Copy and paste the entire script into the document you just created.  Copy the script into the BlueZone \scripts folder.

Launch the BlueZone Script Host and Debugger program.  Select File:Open from the MenuBar.  Locate the script you just created and highlight it and click the Open button.  The script will now be presented in the main window.

Sample Visual Basic Script

' Sample Visual Basic script using BlueZone Host Automation Object

'

' This sample script will run a BlueZone session and then

' logon to a iSeries system and write the Job Log to the disk

' file C:\JOBLOG.TXT.

'

 

' Subroutine Main

'

Sub Main

 

' Instantiate a handle to BHAO

'

Set Host = CreateObject( "BZWhll.WhllObj" )

 

' Run BlueZone iSeries Display

' with session id of S1

' no config file(use settings from Registry)

' timeout and return error if no signon screen after 30 seconds

' continue with script execution after host sends 1 screen paint

'

Retval = Host.OpenSession( 1, 1, "", 30, 1 )

If ( Retval ) Then

   Host.MsgBox "Error connecting to host!", 48

   EndSub

End If

 

' connect to session with hllapi id of "A"

' return error if session not found

'

Retval = Host.Connect( "A" )

If ( Retval ) Then

   Host.MsgBox "Error connecting to session A!", 48

   EndSub

End If

 

' logon to host

' then wait for host to unlock the keyboard

'

Host.SendKey "guest@Tguest@E"

Host.WaitReady 10, 1

 

' go to Display Job Log screen

Host.SendKey "1@E"

Host.WaitReady 10, 1

Host.SendKey "1@E"

Host.WaitReady 10, 1

Host.SendKey "10@E"

Host.WaitReady 10, 1

 

' create disk file C:\JOBLOG.TXT

'

Set fso = CreateObject( "Scripting.FileSystemObject" )

Set f = fso.OpenTextFile( "c:\joblog.txt", 2, True )

 

' write the job log screens to disk

' read the screens until "Bottom" is found at position

' row 19, column 74

'

MoreText = "More.."

BottomText = "Bottom"

While MoreText <> BottomText

   For i = 1 to 24

      Host.ReadScreen Buf, 80, i, 1

      f.WriteLine Buf

   Next

   f.WriteLine " "

   Host.ReadScreen MoreText, 6, 19, 74

Wend

 

' close the file

'

f.Close

 

' logoff from host

'

Host.SendKey "@E"

Host.WaitReady 10, 1

Host.SendKey "@3"

Host.WaitReady 10, 1

Host.SendKey "90@E"

Host.WaitReady 10, 1

 

' close BlueZone iSeries Display

' having session id of S1

'

Host.CloseSession 1, 1

 

' end of Subroutine Main

'

End Sub

 

' run Subroutine Main

'

Main


Sample HTML Page with VBScript

This script is designed to be used with BlueZone Web-to-Host running in the Embedded Client mode.  This script will launch a BlueZone iSeries (AS/400) Display session from an Object Tag.  Four buttons will appear at the top of the web page.  Once the display session is launched, you can use the buttons to sign on to the host and check for any messages, exit the message screen, log off the host and disconnect the BlueZone Object.  The script uses the sign name “guest3”, and the password “guest3”.  You will need to change the script with a valid sign on and password before testing.

The sample also contains the "ScriptOnInitComplere" PARAM shown here:

<PARAM NAME="ScriptLanguage" VALUE="VBScript">

<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 Enable Optional Components” located in the BlueZone Web-to-Host Administrator’s Guide in the “How To Guide – Configuration Related” section, for more information.

Sample HTML Page with VBScript for use with BlueZone Web-to-Host Embedded Client

<HTML>

<HEAD>

 

<SCRIPT language="VBScript">

 

' declare variable host

Dim host

 

' create function hostConn

Function hostConn

 

' instantiate the BlueZone Object

Set host = CreateObject( "BZWhll.WhllObj" )

 

' connect to session A

retval = host.Connect( "A" )

If ( retval ) Then

 

' display an error message if can't connect

host.MsgBox "Error connecting to session A!", 48

End If

End Function

 

' sign on to host and check messages

Function signOn_onClick

host.SendKey "guest3@Tguest3@E"

host.WaitReady 10, 1

host.SendKey "1@E"

host.WaitReady 10, 1

host.SendKey "2@E"

host.WaitReady 10, 1

host.focus

End Function

 

' exit from messages screen

Function exitMsg_onClick

host.SendKey "@3"

host.WaitReady 10, 1

host.focus

End Function

 

' sign off from host

Function signOff_onClick

host.SendKey "90@E"

host.WaitReady 10, 1

host.focus

End Function

 

' disconnect the BlueZone Object

Function disconnObj_onClick

host.disconnect

End Function

 

</SCRIPT>

 

</HEAD>

<BODY>

 

<DIV Style="Position:Absolute;Left:10px;Top:50px">

<OBJECT ID="Seagull Web-to-host Control Module v3"

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="AD_S1">

<PARAM NAME="AD_DistFile" VALUE="default.dst">

<PARAM NAME="AD_S1" VALUE="default.zad">

<PARAM NAME="AD_S1_Save" VALUE="Yes">

<PARAM NAME="AD_S1_RunInBrowser" VALUE="Position">

<PARAM NAME="ScriptLanguage" VALUE="VBScript">

<PARAM NAME="ScriptOnInitComplete" VALUE="hostConn">

</OBJECT>

</DIV>

 

<FORM name="Form">

<INPUT type=button name=signOn value="Sign On" onClick>

<INPUT type=button name=exitMsg value="Exit Messages" onClick>

<INPUT type=button name=signOff value="Sign Off" onClick>

<INPUT type=button name=disconnObj value="Disconnect" onClick>

</FORM>

 

</BODY>

</HTML>


Sample HTML Page with JavaScript

This script is designed to be used with BlueZone Web-to-Host running in the Embedded Client mode.  This script will launch a BlueZone iSeries (AS/400) Display session from an Object Tag.  Four buttons will appear at the top of the web page.  Once the display session is launched, you can use the buttons to sign on to the host and check for any messages, exit the message screen, log off the host and disconnect the BlueZone Object.  The script uses the sign name “guest3”, and the password “guest3”.  You will need to change the script with a valid sign on and password before testing.

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 Enable Optional Components” located in the BlueZone Web-to-Host Administrator’s Guide in the “How To Guide – Configuration Related” section, for more information.

Sample HTML Page with JavaScript for use with BlueZone Web-to-Host Embedded Client

<HTML>

<HEAD>

 

<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" );

 

//connect to session A

resultCode = host.Connect( "A" );

if ( resultCode != 0 )

 

//display an error message if can't connect

host.MsgBox( "Error connecting to session A!", 48 );

}

 

// sign on to host and check messages

function signOn() {

host.SendKey( "guest3@Tguest3@E" );

host.WaitReady ( 10, 1 );

host.SendKey( "1@E" );

host.WaitReady( 10, 1 );

host.SendKey( "2@E" );

host.WaitReady( 10, 1 );

host.Focus();

}

 

// exit from messages screen

function exitMsg() {

host.SendKey( "@3" );

host.WaitReady( 10, 1 );

host.focus();

}

// sign off from host

function signOff() {

host.SendKey( "90@E" );

host.WaitReady( 10, 1 );

host.focus();

}

// disconnect the BlueZone Object

function disconnObj() {

host.disconnect();

}

 

</SCRIPT>

 

</HEAD>

<BODY>

 

<DIV Style="Position:Absolute;Left:10px;Top:60px">

<OBJECT ID="Seagull Web-to-host Control Module v3"

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="AD_S1">

<PARAM NAME="AD_DistFile" VALUE="default.dst">

<PARAM NAME="AD_S1" VALUE="default.zad">

<PARAM NAME="AD_S1_Save" VALUE="No">

<PARAM NAME="AD_S1_RunInBrowser" VALUE="Position">

<PARAM NAME="ScriptLanguage" VALUE="JavaScript">

<PARAM NAME="ScriptOnInitComplete" VALUE="hostConn()">

</OBJECT>

</DIV>

 

<FORM>

<INPUT NAME="submit" TYPE=Button VALUE="Sign On" onClick="signOn()">

<INPUT NAME="submit" TYPE=Button VALUE="Exit Messages" onClick="exitMsg()">

<INPUT NAME="submit" TYPE=Button VALUE="Sign Off" onClick="signOff()">

<INPUT NAME="submit" TYPE=Button VALUE="Disconnect" onClick="disconnObj()">

</FORM>

 

</BODY>

</HTML>