Sign in to follow this  
Followers 0
wills

Help with WinGetText()

10 posts in this topic

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.

Share this post


Link to post
Share on other sites



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")

Share this post


Link to post
Share on other sites

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")

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

If WinGetText() <> 0 ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0