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

Any way to make a macro wait until a string changes?

Status
Not open for further replies.

hotbread

Technical User
Mar 13, 2006
42
AU
Hi guys... this is my first post here, and just wondering if you can help me with a problem.

I'm wanting to have a macro act as soon as a string (or character) on the screen changes. Similar to the WaitForString concept, but rather than waiting for a particular string, I want it to wait until the specified string changes. Is there a way to do this?

I tried....
If Not Sess0.Screen.WaitForString(x,23,1)

But this didn't work - because the screen always began with the x string at location 23,1 the above line returned False immediately, without waiting for the change.

I also tried...
If Sess0.Screen.WaitForString(Not x,23,1)

But this was just a guess on my part and didn't work!

Any suggestions would be very appreciated!
 
Use a loop:

Do while Sess0.Screen.GetString(23,1) = x
doevents
Loop

When the loop exits it's because the string changed.

Be careful with infinite loops, they can cause a program to hang. You may want to put a counter in the loop to give an error if the string hasn't changed in 10000 tries or so.

calculus
 
Code:
Stemp = Sess0.Screen.GetString(x,21,1)
began = timer
Same = True

Do 
  DoEvents ' stops pc fan from helicoptering 
  If Stemp <> Sess0.Screen.GetString(x,21,1) then Same = False
loop until not Same or timer - began => 10

'waits for change in vairable or 10 seconds whichever comes first

Loop with 10 second TimeOut
 
Thanks very much for your help calculus & MgWills..... great suggestions that I intend to try as soon as I get to work!
 


Hi,

In the code that I have inherited, I have seen this...
Code:
datarefreshed = MyScrn.[b]waitforcursor(3, 17)[/b]
If datarefreshed then
...


Skip,

[glasses] [red]Be Advised![/red] A chicken, who would drag a wagon across the road for 2 cents, is…
POULTRY in motion to PULLET for a PALTRY amount! [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top