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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel & Attachmate Timing? 2

Status
Not open for further replies.

jhall01

Programmer
Jul 3, 2003
328
US
Here is my VBA code:
Code:
Sub set_settleTime()
   
    xtraSettleTime = 3000
    
    OldSystemTimeout = System.TimeoutValue
    If xtraSettleTime > OldSystemTimeout Then
        System.TimeoutValue = xtraSettleTime
    End If
    
End Sub
Code:
...
call set_settleTime
...
With MyScn
    .SendKeys (npa)
    .SendKeys (nxx)
    .SendKeys (line)
    .SendKeys ("<Pf2>")
    compName = .GetString(3, 2, 25)
    .PutString "CPNI", 1, 6
    .SendKeys ("<Pf3>")
    .SendKeys ("<Pf3>")
End With
...

I run this and the Putstring doesn't fire.

But if I manually run the VB6 macro by stepping in...everything runs just fine. Do i need to put some delays in the macro? is this a timing issue between Excel and Attachmate? The default timeout is set to 30000 and doesnt change because it is set so high
 
Hah, found a solution:

Code:
With MyScn
    .SendKeys (npa)
    .SendKeys (nxx)
    .SendKeys (line)
    .SendKeys ("<Pf2>")
End With
    [COLOR=red]Application.Wait (Now + TimeValue("0:00:01"))[/color]
    compName = MyScn.GetString(3, 2, 25)
    MyScn.PutString "CPNI", 1, 6
    [COLOR=red]Application.Wait (Now + TimeValue("0:00:01"))[/color]
    MyScn.SendKeys ("<Pf3>")
    [COLOR=red]Application.Wait (Now + TimeValue("0:00:01"))[/color]
    MyScn.SendKeys ("<Pf3>")

This forces the macro to wait 1 second between the slow steps. Is there a better way to do this? Is there a way to speed it up to half a second instead of a full second?
 
You found the problem, but you're handling it the hard way.

If you'd like to use the default time, then call:
MyScn.WaitHostQuiet(xtraSettleTime)

A much better way to handle this is:

Code:
Do while MyScn.OIA.Xstatus <> 0 
   Doevents
Loop

This code will wait until the "X Clock" in Extra is gone.

calculus
 
So just for curiousity, I would put that loop after every step i need to wait on?

ie

Code:
    Do while MyScn.OIA.Xstatus <> 0
       Doevents
    Loop 
    compName = MyScn.GetString(3, 2, 25)
    MyScn.PutString "CPNI", 1, 6
    Do while MyScn.OIA.Xstatus <> 0
       Doevents
    Loop 
    MyScn.SendKeys ("<Pf3>")
    Do while MyScn.OIA.Xstatus <> 0
       Doevents
    Loop 
    MyScn.SendKeys ("<Pf3>")
    Do while MyScn.OIA.Xstatus <> 0
       Doevents
    Loop

If this is the case sould i create a function and use that to eliminate code?

Code:
Public Function Sleep()
    Do While MyScn.OIA.XStatus <> 0
        DoEvents
    Loop
End Function

Public Sub test()
    ...
    compName = MyScn.GetString(3, 2, 25)
    MyScn.PutString "CPNI", 1, 6
    Sleep
    MyScn.SendKeys ("<Pf3>")
    Sleep
    MyScn.SendKeys ("<Pf3>")
    Sleep
    ...
End Sub
 
I have found a couple of other posts very similar to mine. I actually made my sleep() and added 3 Xstatus loops. It seems that Excel and Attachmate are not syncing up.

The problem, excel is moving too fast for Attachmate. Does the Xstatus loop slow down excel or Attachmate?

I have even tried setting
MyScn.WaitHostQuiet(3000) and MyScn.WaitForString "mystring"

that doesn't help at all. Everything I try seems to not work. Excel just keeps moving through its code too fast. Should the MyScn object properties/methods slow down the Application(excel) object?
 
Your first post is correct. Putting the Loop in a function is very helpful.

As to the sync up problem...
The loop will only wait for the "X Clock" to disappear from Extra. It can still happen that your app will hit the "X Clock" several times.

What I put in my function is:

Wait "Action", Optional WaitForString

This allows me to send an "Enter", and then optionally wait for a specific string to appear in Extra. This will handle most cases, but occasionally I need a Pass/Fail. For this I created a WaitWithFail that is pretty complex (even to use) as it has input of arrays for pass and fail to look for.

Good coding...
calculus
 
for those having problems with timing issues here is one possible issue to fix:

set your .WaitHostQuiet object to a variable:

Code:
boolSleep = MyScn.WaitHostQuiet(xtraSettleTime)

this forces the Excel to wait for boolSleep to be set to "True" before it moves on in the code.

I was previously using

Code:
MyScn.WaitHostQuiet(xtraSettleTime)

but excel was moving on since it wasn't being set to anything.

I actually made myself a function to look for a specific screen:

Code:
Public Function waitScreen(AMString as String)
  [COLOR=green]'Wait for xtraSettletime milliseconds[/color]
  waitScreen = MyScn.WaitForString(Amstring,,,,,xtraSettleTime)
  [COLOR=green]'Wait again for good measure but only wait for half a second[/color]
  waitScreen = MyScn.WaitForString(Amstring,,,,,500)

[COLOR=green]/*i also added another wait code here but passed it to a variable instead of back to the function to force a wait if the string was found, i pass to a variable to maintain the TRUE/FALSE return of the function to be used for evaluating if the string was found for code flow */[/color]

waitmore = MyScn.WaitHostQuiet(500)

End Function
 
BTW - Thanks for the help calculus, as always you are a tremendous help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top