I think my code is pretty sound. The only time it would go on a infinite loop is if a user sends keyboard commands to the session while the macro is running (I know I can hide the session while it runs but my users are not savvy enough to kill an application that they can't see) or the session times out while the excel loop is running. My biggest worry is using the WaitHostQuiet (g_HostSettleTime) while the screen changes. If the host is pretty busy I usually get thrown on the infinite loop. Just occurred to me... can I limit the times a loop is run? So even if the something goes wrong the macro will stop after x amount of loops. Here is part of my code: CODESet MyRange = Application.ActiveWorkbook.ActiveSheet.Range("B:B") Dim Row As Long Sess0.WindowState = xMINIMIZED
For Row = 3 To MyRange.Rows.Count Sess0.Screen.WaitHostQuiet (g_HostSettleTime) Application.Wait (Now + TimeValue("0:00:01")) Do If UCase(Sess0.Screen.GetString(2, 74, 6)) <> "CLOSED" Then Exit Do 'ElseIf UCase(Sess0.Screen.GetString(3, 6, 3)) = "END" Then 'Exit Do ElseIf UCase(Sess0.Screen.GetString(2, 74, 6)) = "CLOSED" Then Sess0.Screen.SendKeys ("<PF8>") Sess0.Screen.WaitHostQuiet (g_HostSettleTime) End If Loop Until UCase(Sess0.Screen.GetString(3, 6, 3)) = "END" If UCase(Sess0.Screen.GetString(2, 74, 7)) = "PENDING" Then xlSheet.Cells(Row + 1, 1).Value = Sess0.Screen.GetString(1, 47, 4) 'LINE # xlSheet.Cells(Row + 1, 2).Value = Trim(Sess0.Screen.GetString(12, 2, 5)) 'QTY # xlSheet.Cells(Row + 1, 3).Value = Sess0.Screen.GetString(9, 75, 2) 'UM# xlSheet.Cells(Row + 1, 4).Value = Trim(Sess0.Screen.GetString(9, 2, 26)) 'PART # xlSheet.Cells(Row + 1, 5).Value = Trim(Sess0.Screen.GetString(9, 64, 9)) 'KEYWORD # xlSheet.Cells(Row + 1, 6).Value = Trim(Sess0.Screen.GetString(12, 8, 4)) 'TERMS # xlSheet.Cells(Row + 1, 7).Value = "PENDING" 'NET PRICE xlSheet.Cells(Row + 1, 8).Value = "PENDING" 'EXTENDED PRICE xlSheet.Cells(Row + 1, 9).Value = "CALL CUST SVC" 'DISC Sess0.Screen.SendKeys ("<PF8>") Sess0.Screen.WaitHostQuiet (g_HostSettleTime) ElseIf UCase(Sess0.Screen.GetString(2, 74, 6)) <> "CLOSED" Then xlSheet.Cells(Row + 1, 1).Value = Sess0.Screen.GetString(1, 47, 4) 'LINE # xlSheet.Cells(Row + 1, 2).Value = Trim(Sess0.Screen.GetString(12, 2, 5)) 'QTY # xlSheet.Cells(Row + 1, 3).Value = Sess0.Screen.GetString(9, 75, 2) 'UM# xlSheet.Cells(Row + 1, 4).Value = Trim(Sess0.Screen.GetString(9, 2, 26)) 'PART # xlSheet.Cells(Row + 1, 5).Value = Trim(Sess0.Screen.GetString(9, 64, 9)) 'KEYWORD # xlSheet.Cells(Row + 1, 6).Value = Trim(Sess0.Screen.GetString(12, 8, 4)) 'TERMS # xlSheet.Cells(Row + 1, 7).Value = Trim(Sess0.Screen.GetString(12, 57, 10)) 'NET PRICE xlSheet.Cells(Row + 1, 8).Value = Trim(Sess0.Screen.GetString(12, 71, 16)) 'EXTENDED PRICE 'xlSheet.Cells(row + 1,9).value = Sess0.Screen.GetString(12,49,4) 'DISC If UCase(Sess0.Screen.GetString(2, 74, 4)) = "OPEN" And (Sess0.Screen.GetString(12, 20, 5)) = " 0.00" Then xlSheet.Cells(Row + 1, 7).Value = "N/A" 'NET PRICE xlSheet.Cells(Row + 1, 8).Value = "N/A" 'EXTENDED PRICE 'xlSheet.Cells(row + 1,9).value = "N/A" 'DISC End If If Trim(Sess0.Screen.GetString(20, 36, 2)) > "0" Then xlSheet.Cells(Row + 1, 9).Value = "IN STOCK" Else xlSheet.Cells(Row + 1, 9).Value = "OUT OF STOCK" 'HAZ End If Sess0.Screen.SendKeys ("<PF8>") Sess0.Screen.WaitHostQuiet (g_HostSettleTime) End If Sess0.Screen.WaitHostQuiet (g_HostSettleTime) 'Application.Wait (Now + TimeValue("0:00:01")) If UCase(Sess0.Screen.GetString(3, 44, 2)) = "NO" Then Exit For Next Row |
|