CrazyConfused Posted December 22, 2010 Share Posted December 22, 2010 Hi all, Hate to have to start a new topic for this but I have been unable to find an existing thread that address's my issue. I have written some code that uses ControlGetText to check if the text field has the proper value in it and if not I use ControlSend to insert the proper value. I found that if I change the ControlID to something that does not exist the script continues as if nothing has happened. I would like to be able to verify if a field exists. I would also like to be able to verify if a button exists. I thought maybe I could use the return value in ControlClick to figure out if I was successful or not but so far the only value I get back is 0 for failure. This happens both when I have the correct ControlID (and the click works) and when I enter an incorrect ControlID. WinWaitActive("Reports") MsgBox(4096,"",@error) SetError(2) MsgBox(4096,"",@error) ControlClick("Reports", "", "[CLASS:ThunderRT6PictureBoxDC; INSTANCE:3]") ;Run Reports Button MsgBox(4096,"",@error) I am using MsgBox in an attempt to track what is going on. When I first run this code @error equals 0 and then it changes to 2 (I intentionally set it to something different from 0 or 1 to make sure things are working properly). When I have the correct ControlID in the code the next message box displays 0 BUT I see the screen change as it is supposed to when this button is clicked. When I have the wrong ControlID in the code the next message box displays 0 (and nothing happens). I kind of figure I am making some stupid mistake in how I use @error but after trolling forums and help file I haven't been able to figure out what my problem is. Whats my problem? Is there a better way to verify a button or field's existence than by using the return value? Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 22, 2010 Share Posted December 22, 2010 Try it this way: $hButton = ControlGetHandle("Reports", "", "[CLASS:ThunderRT6PictureBoxDC; INSTANCE:3]") If $hButton Then ControlClick("Reports", "", $hButton) ;Run Reports Button Else MsgBox(16, "Error", "Button not found.") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
CrazyConfused Posted December 23, 2010 Author Share Posted December 23, 2010 Thanks PsaltyDS! I had tried working with ControlGetHandle for a bit but I was trying to use the @error (still confused about the whole return value @error thing but meh) return value as described in AutoIt Help. That code works great and I have been able to use it for both buttons and text fields. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now