Script Host sample script

'

' Sample Visual Basic script using BlueZone Script Host

'

' This sample script will run a BlueZone session and then 

' logon to a AS/400 system and write the Job Log to the disk 

' file C:\JOBLOG.TXT.

'

' Subroutine Main

Sub Main

' Run BlueZone AS/400 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 = OpenSession( 1, 1, "", 30, 1 )

If ( Retval ) Then

   MsgBox "Error connecting to host!", 48

   EndSub

End If

' connect to session with hllapi id of "A"

' return error if session not found

'

Retval = EMConnect( "A" )

If ( Retval ) Then

   MsgBox "Error connecting to session A!", 48

   EndSub

End If

' logon to host

' then wait for host to unlock the keyboard

'

' Note: Mainframe sessions will need to enter the number

' of keyboard restores sent from the host system as

' parameter 2 in EMWaitReady ... not needed and is 0

' for AS/400 scripting.

'

EMSendKey "guest3@Tguest3@E"

EMWaitReady 10, 0

' go to Display Job Log screen

EMSendKey "1@E"

EMWaitReady 10, 0

EMSendKey "1@E"

EMWaitReady 10, 0

EMSendKey "10@E"

EMWaitReady 10, 0

' 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

      EMReadScreen Buf, 80, i, 1

      f.WriteLine Buf

   Next

   f.WriteLine " "

   EMReadScreen MoreText, 6, 19, 74

Wend

' close the file

'

f.Close

' logoff from host

'

EMSendKey "@E"

EMWaitReady 10, 0

EMSendKey "@3"

EMWaitReady 10, 0

EMSendKey "90@E"

EMWaitReady 10, 0

' close BlueZone AS/400 Display

' having session id of S1

'

CloseSession 1, 1

' end of Subroutine Main

'

End Sub

' run Subroutine Main

'

Main