'----------------------------------------------------------------------
' This macro was created by the macro recorder.
' Macro File: shopfloor.ebs
' Date: Wed May 18 09:57:00 2016
' Recorded for profile: WJ Shopfloor
'----------------------------------------------------------------------

Sub Main
  Dim HostExplorer as Object
  Dim MyHost as Object
  Dim Rc as Integer

  Dim iPSUpdateTimeout
  Dim iWaitForStringTimeout

  On Error goto GenericErrorHandler

  Set HostExplorer = CreateObject("HostExplorer") ' Initialize HostExplorer Object
  Set MyHost = HostExplorer.HostFromProfile("WJ Shopfloor") ' Set object for the desired session
  If MyHost is Nothing Then Goto NoSession

  iPSUpdateTimeout = 60       ' WaitPSUpdated timeout set to 60 seconds
  iWaitForStringTimeout = 60  ' WaitForString timeout set to 60 seconds

  Rc = MyHost.WaitForString( "Username:", -1, iWaitForStringTimeout, TRUE )
  If Rc = 0 Then Goto OnWaitForStringTimeout
  Rc = MyHost.Keys("shop_xmi^M")
  Rc = MyHost.WaitPSUpdated( iPSUpdateTimeout, TRUE )
  If Rc <> 0 Then Goto OnWaitPSUpdatedTimeout
  Rc = MyHost.WaitForString( "Password:", -1, iWaitForStringTimeout, TRUE )
  If Rc = 0 Then Goto OnWaitForStringTimeout
  Rc = MyHost.Keys("dnc123^M")
  Rc = MyHost.WaitPSUpdated( iPSUpdateTimeout, TRUE )
  If Rc <> 0 Then Goto OnWaitPSUpdatedTimeout
  Rc = MyHost.WaitForString( "| EXIT                                     |                                   |", -1, iWaitForStringTimeout, TRUE )
  If Rc = 0 Then Goto OnWaitForStringTimeout
  Exit Sub

'-------------------- Runtime Error Handlers --------------------
GenericErrorHandler:
  Msgbox "Error " & Err & " : """ & Error(Err) & """ has occurred on line " & Erl-1 & "." & Chr(10) & "Unable to continue macro execution.", 16, "HostExplorer Basic Macro Error"
  Exit Sub

NoSession:
  Msgbox "Profile ""WJ Shopfloor"" is not running." & Chr(10) & "Unable to execute macro.", 16, "HostExplorer Macro Error"
  Exit Sub

OnWaitPSUpdatedTimeout:
  Msgbox "Timeout occured waiting for host to update screen." & Chr(10) & "Unable to continue macro execution.", 16, "HostExplorer Basic Macro Error"
  Exit Sub

OnWaitForStringTimeout:
  Msgbox "Timeout occured waiting for string on host screen." & Chr(10) & "Unable to continue macro execution.", 16, "HostExplorer Basic Macro Error"
  Exit Sub

End Sub
