wills Posted August 4, 2011 Posted August 4, 2011 This is probably a stupid question, but here goes: Per the AutoIt function reference, WinGetText() returns a string, or a numeric zero to indicate an error. So how do I detect an error? If I do the obvious, which is to compare the returned value to zero, the test always passes, because AutoIt automatically converts strings to zero when used in comparisons with numeric values. Any ideas? Thanks in advance.
Bert Posted August 4, 2011 Posted August 4, 2011 A few REAL simple ways(but not the best way): $msg = WinGetText("windowname") msgbox(0, "", @error) or this: $msg = WinGetText("windowname") ConsoleWriteError ($msg) The best way if you are deploying something is to have the error written to a log file. If you want to just detect when the @error equals when a certain error happens then use an IF statement: IF @error = 0 then msgbox(0, "", "error") The Vollatran project My blog: http://www.vollysinterestingshit.com/
wills Posted August 4, 2011 Author Posted August 4, 2011 MPH: Thanks for your reply.The function reference for WinGetText() doesn't mention @ERROR, and a quick test revealed that it isn't set by WinGetText() to indicate an error; it would be nice if it were, for consistency with other functions, and because it makes more sense than mixing data types.A few REAL simple ways(but not the best way):$msg = WinGetText("windowname")msgbox(0, "", @error)or this:$msg = WinGetText("windowname")ConsoleWriteError ($msg)The best way if you are deploying something is to have the error written to a log file. If you want to just detect when the @error equals when a certain error happens then use an IF statement:IF @error = 0 then msgbox(0, "", "error")
Moderators SmOke_N Posted August 4, 2011 Moderators Posted August 4, 2011 (edited) Global $gs_Text1 = __WinGetText("") ConsoleWrite(@error & @CRLF) Global $gs_Text2 = __WinGetText("RandomTitleDoesNotExist") ConsoleWrite(@error & @CRLF) Func __WinGetText($v_title, $s_text = "") Local $v_text = WinGetText($v_title, $s_text) Return SetError(IsInt($v_text), 0, $v_text) EndFunc Edited August 4, 2011 by SmOke_N Provided better example Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
wills Posted August 4, 2011 Author Posted August 4, 2011 Perfect! Thanks SmOke_N! Global $gs_Text1 = __WinGetText("") ConsoleWrite(@error & @CRLF) Global $gs_Text2 = __WinGetText("RandomTitleDoesNotExist") ConsoleWrite(@error & @CRLF) Func __WinGetText($v_title, $s_text = "") Local $s_rettext = WinGetText($v_title, $s_text) Return SetError(Not IsString($s_rettext), 0, $s_rettext) EndFunc
Moderators SmOke_N Posted August 4, 2011 Moderators Posted August 4, 2011 NP, I like the IsInt() option better... see my edit. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Moderators SmOke_N Posted August 4, 2011 Moderators Posted August 4, 2011 (edited) If WinGetText() <> 0 ? @Monoscout Your way would work "most of the time", however, if the window you're trying to get text from, had text that equaled zero, then it would return a false positive. Proof Example:If "0" <> 0 Then MsgBox(64 + 262144, "Works", "Your way would work.") Else MsgBox(16 + 262144, "Oops", "AuotIt tries to determine string integer in match cases.") EndIf There you see I am comparing a string integer to an actual integer, but you don't get the results you necessarily expect to. Edited August 4, 2011 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
monoscout999 Posted August 4, 2011 Posted August 4, 2011 @Monoscout Your way would work "most of the time", however, if the window you're trying to get text from, had text that equaled zero, then it would return a false positive. Proof Example:If "0" <> 0 Then MsgBox(64 + 262144, "Works", "Your way would work.") Else MsgBox(16 + 262144, "Oops", "AuotIt tries to determine string integer in match cases.") EndIf There you see I am comparing a string integer to an actual integer, but you don't get the results you necessarily expect to. So... the IsInt() or NOT IsString() would be more correct to identify the error. PD: This have to be reported like a bug i guess or maybe it have a logical explanation.
Moderators SmOke_N Posted August 4, 2011 Moderators Posted August 4, 2011 So... the IsInt() or NOT IsString() would be more correct to identify the error.I would assume so.PD: This have to be reported like a bug i guess or maybe it have a logical explanation.I believe it's by design. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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