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!

Stop all Macros Button

Status
Not open for further replies.

Losman500

Technical User
Oct 9, 2007
43
US
Hello,

So my macro that puts data from Attachmate to Excel just went on an infinite loop (I know that if it was well written this should never happen). I would like to know if there a way to write a macro that will stop all running macros and assign it to a toolbar button in Attachmate (sort of a "panic button")

Right now the only way I can stop the loop is by closing Attachmate. Also for this particular case I wrote the macro in Excel but most of my other macros are written in Attachamate so I would like to know how to deal with both scenarios.

You help is much appriciated
 
no doubt you have already discovered that the "Stop Macro" button that is available for your Attachmate toolbar, does not work worth a darn.

I look forward to a functional response to your post!
 



Hi,

Rather than a panic button, (the only panic button I know of is to kill the application), use the step feature to observe what's happening in your loop and fix it.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
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:

Code:
Set 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


 


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.
Try moving the cursor OFF the settle coordinates after issuing a send keys, and then WaitForCursor in a do loop.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
i usually do something like this:

Code:
    ct = 0
    Sess0.Screen.Sendkeys("<right><ENTER>")  'move the cursor from original position
    Do While Sess0.Screen.OIA.Xstatus <> 0
    DoEvents
    Loop
    Do
    ct = ct + 1                             
    If ct = 100 Then exit Do                'add ct to exit Do if it exceeds "x" times
    Loop until _                            'wait for where cursor should be
    Sess0.Screen.Row = 8 And _
    Sess0.Screen.Col = 15
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top