Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HostSettle... more info for beginner pleease 1

Status
Not open for further replies.

NWildblood

Technical User
Nov 12, 2007
113
GB
Hi, I have a piece of code I'd love to re-write without all the Sess0.Screen.WaitHostQuiet (g_HostSettleTime)

Can anyone assist ?

I'm generating some jobs in Extra screen from and Excel, getting the new job numbers once they are generated, then pasting them back in the excel spreadsheet for the client.

I'd really like to slick things up by using

Do While Sess.Screen.OAI.Xstatus <> 0

Or similar, but my EB knowledge is still at monkey-see monkey do... can anyone show me the way??



Sub CreateJobWithIF()
'Test To create jobs with an IF statement
'--------------------------------------------------------------------------------
' Get the main system object
Dim i_cols As Integer, msg_line As String
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
Set Sessions = System.Sessions

If (Sessions Is Nothing) Then
MsgBox "Could not create the Sessions collection object. Stopping macro playback."
Stop
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 50 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim CSS As Object
Set CSS = GetObject("C:\Documents and Settings\zeicri\Desktop\SMNXS06.edp")
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 Is Nothing) Then
MsgBox "Could not create the Session object. Stopping macro playback."
Stop
End If

If Not Sess0.Visible Then Sess0.Visible = True
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)

i_cols = Sess0.Screen.Cols
msg_line = Trim(Sess0.Screen.GetString(24, 1, i_cols))

xlrow = 3

Sess0.Screen.SendKeys ("<Home>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("ASMJ")
Sess0.Screen.SendKeys ("<Enter>")


Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
'Sess0.Screen.SendKeys ("<Tab>")


Do While Trim(Range("A" & xlrow).Value) <> ""

Sess0.Screen.SendKeys ("HQjob<NewLine><Tab>IPT")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys (Trim(Range("E" & xlrow).Value))
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<NewLine>mx")
Sess0.Screen.SendKeys (Trim(Range("g" & xlrow).Value))
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<Tab>")
Sess0.Screen.SendKeys (Trim(Range("H" & xlrow).Value))
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<NewLine><NewLine>A<Tab><NewLine><Delete><EraseEOF>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys (Trim(Range("J" & xlrow).Value))
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<NewLine>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys (Trim(Range("K" & xlrow).Value))
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<NewLine><NewLine>")
Sess0.Screen.SendKeys (Trim(Range("L" & xlrow).Value))
Sess0.Screen.SendKeys (Trim(Range("M" & xlrow).Value))
Sess0.Screen.SendKeys (Trim(Range("N" & xlrow).Value))
Sess0.Screen.SendKeys ("exxxHQ<NewLine><NewLine>803206425<Enter>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
If InStr(1, UCase(msg_line), UCase("TW007 - Required by Date less than End Date")) > 0 Then
Sess0.Screen.PutString "y", 24, 62 ' location of "y"
Sess0.Screen.SendKeys ("<Enter>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
End If
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<Enter>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("y")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<Enter><Enter>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)

Range("R" & xlrow).Value = Trim(Sess0.Screen.GetString(22, 30, 6))
xlrow = xlrow + 1

Sess0.Screen.SendKeys ("<Pf9>")




Loop

MsgBox "DONE", vbOKOnly, "End of Batch"
System.TimeoutValue = OldSystemTimeout
End Sub


----
Thanks !
 
You can replace all of your "Sess0.Screen.WaitHostQuiet (g_HostSettleTime)" with "Do While Sess0.Screen.OIA.XStatus <> 0 : Loop"

I had been putting a WaitHostQuiet in the middle of that loop but I learned from ChrisWhite123 that omitting it saves tons of time in how fast the macro can run.
 
Thanks streetprog, I understand the principle here (just) but now the dang thing's only populating the first few fields then returning the complete msg ! Having removed the Sess0.Screen.WaitHostQuiet (g_HostSettleTime) and putting the "do while" at the end of the script. How would you actually code this (sorry, I really am new to this, many thanks again)
 
You have to put Call Wait(Sess) after any keypress that will trigger the Xclock (example: <ENTER>, <Pf8>, etc).

Code:
' Untested

Sub CreateJobWithIF()
   Dim System As Object, Sessions As Object, Sess As Object, CSS As Object
   Dim msg_line As String

   Set System = CreateObject("EXTRA.System")   ' Gets the system object

   If (System Is Nothing) Then
      MsgBox "Could not create the EXTRA System object.  Stopping macro playback."
      Stop
   End If

   Set Sessions = System.Sessions

   If (Sessions Is Nothing) Then
      MsgBox "Could not create the Sessions collection object.  Stopping macro playback."
      Stop
   End If

   Set CSS = GetObject("C:\Documents and Settings\zeicri\Desktop\SMNXS06.edp")
   Set Sess = System.ActiveSession

   If (Sess Is Nothing) Then
      MsgBox "Could not create the Session object.  Stopping macro playback."
      Stop
   End If

   If Not Sess.Visible Then Sess.Visible = True
   
   msg_line = Trim(Sess.Screen.GetString(24, 1, Sess.Screen.Cols))
   xlrow = 3

   Sess.Screen.SendKeys ("<Home>ASMJ<Enter>")
   Call Wait(Sess)

   'Sess.Screen.SendKeys ("<Tab>")

   Do While Trim(Range("A" & xlrow).Value) <> ""
      Sess.Screen.SendKeys ("HQjob<NewLine><Tab>IPT")
      Sess.Screen.SendKeys (Trim(Range("E" & xlrow).Value))
      Sess.Screen.SendKeys ("<NewLine>mx")
      Sess.Screen.SendKeys (Trim(Range("G" & xlrow).Value))
      Sess.Screen.SendKeys ("<Tab>")
      Sess.Screen.SendKeys (Trim(Range("H" & xlrow).Value))
      Sess.Screen.SendKeys ("<NewLine><NewLine>A<Tab><NewLine><Delete><EraseEOF>")
      Sess.Screen.SendKeys (Trim(Range("J" & xlrow).Value))
      Sess.Screen.SendKeys ("<NewLine>")
      Sess.Screen.SendKeys (Trim(Range("K" & xlrow).Value))
      Sess.Screen.SendKeys ("<NewLine><NewLine>")
      Sess.Screen.SendKeys (Trim(Range("L" & xlrow).Value))
      Sess.Screen.SendKeys (Trim(Range("M" & xlrow).Value))
      Sess.Screen.SendKeys (Trim(Range("N" & xlrow).Value))
      Sess.Screen.SendKeys ("exxxHQ<NewLine><NewLine>803206425<Enter>")
      Call Wait(Sess)
      
      If InStr(1, UCase(msg_line), UCase("TW007 - Required by Date less than End Date")) > 0 Then
         Sess.Screen.PutString "y", 24, 62
         Sess.Screen.SendKeys ("<Enter>")
         Call Wait(Sess)
      End If
      
      Sess.Screen.SendKeys ("<Enter>")
      Call Wait(Sess)
      
      Sess.Screen.SendKeys ("y")
      Sess.Screen.SendKeys ("<Enter>")
      Call Wait(Sess)
      
      Sess.Screen.SendKeys ("<Enter>")
      Call Wait(Sess)
      
      Range("R" & xlrow).Value = Trim(Sess.Screen.GetString(22, 30, 6))
      xlrow = xlrow + 1

      Sess.Screen.SendKeys ("<Pf9>")
      Call Wait(Sess)
   Loop

   MsgBox "DONE", vbOKOnly, "End of Batch"
End Sub

Private Sub Wait(Sess As Object)
   Do While Sess.Screen.OIA.Xstatus <> 0
      DoEvents
   Loop
End Sub
 
Also, instead of using
Code:
Sess.Screen.SendKeys ("<Tab>")
Sess.Screen.SendKeys ("<NewLine>")
you should try
Code:
Sess.Screen.PutString a_string, row_num, col_num
Sess.Screen.PutString Trim(Range("E" & xlrow).Value), 3, 1
The numbers at the bottom right portion of the emulation screen shows the position of the cursor (example: 24/05 <- cursor is on row 24, col 5).
 
WinblowsME - Outstanding process time reduction, many thanks !
 
You may experiance problems with the Do While xstatus<>0 because if the users enters an invalid character or other varous situations the xclock can stay at different values therefore creating an infite loop. I have had this situtation in the past. But you can add a select case statement to the sub to catch these situations.
 
Thanks for all of that, but in another realted bit of code I now have a problem with it not obeying the following:

Sess.Screen.WaitForString "TI004 - Modification Successful"

Anyone know why this is not effective ??

Thanks again
 
How is .WaitForString not obeying? Are you getting any error messages? Maybe "TI004 - Modification Successful" never shows up on the screen, so your macro waits until the string shows up on the screen? Or, try
Code:
Sess.Screen.WaitForString UCase("TI004 - Modification Successful")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top