Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Losman500 (TechnicalUser) (OP)
30 Mar 09 12:01
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
mizsydney (TechnicalUser)
7 Apr 09 18:42
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!
SkipVought (Programmer)
7 Apr 09 20:14



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,
glassesDon't let the Diatribe...
talk you to death!tongue

glassesJust traded in my old subtlety...
for a NUANCE!tongue

Losman500 (TechnicalUser) (OP)
9 Apr 09 9:57
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


 
SkipVought (Programmer)
9 Apr 09 10:11


Quote:

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,
glassesDon't let the Diatribe...
talk you to death!tongue

glassesJust traded in my old subtlety...
for a NUANCE!tongue

vzachin (TechnicalUser)
9 Apr 09 10:41
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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close