Jump to content

newbie, syntax help - quick q!!


Recommended Posts

OK this should be a quick one.

I've only just started AutoIt v3, having used v2 for a year or so and I'm finding it quite a change.

I'm trying to do an if function, based on the window text of the current window.

at the moment i've got

Send ("#r")
WinWaitActive ("Run")
Send ("D:\{ENTER}")
WinWaitActive ("Run")
If WinGetText ("") = "This folder was moved or removed" Then
  Sleep (2000)
  Send ("{ENTER}")
  WinWaitActive ("Run")
  Send ("{ESC}")
  Exit
EndIf

Basically what this does it pops up the 'run' box, to check if when the D:\ drive is opened, whether the error message pops up.

I don't think it works though - and I'm pretty sure the problem lies on the If line.

Try it on your machine, start > run > then type a drive letter that doesn't exist and press enter, and see the resulting window.

I'm trying to detect if that window pops up, and do the middle bit of code if that error window does popup. That middle bit of code basically dismisses the error window, and the run window, then exits.

If the current window doesn't equal that text, then I'd like the script to continue with the code after the EndIf

But I'm sure there's a problem with the way I've written the condition in the If statement.

Any help will be appreciated.

Thanks

Link to comment
Share on other sites

Your code is waiting for the "run" window to become active again,

which does not happen if the error message occurs. Because the error message is a modal dialogue and has to be answered before the "run" window becomes active again.

So I'd suggest using the sleep command instead of waiting for the window...

Send ("#r")
WinWaitActive ("Run")
Send ("D:\{ENTER}")

  sleep(500)
  $x = WinGetText ("")
If StringInStr ($x, "This folder was moved or removed") >0 Then
  Sleep (2000)
  Send ("{ENTER}")
  WinWaitActive ("Run")
  Send ("{ESC}")
  Exit
EndIf

Hope this helps.

Marc

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...