AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ControlGet, ..., Line, N returns "error" for empty

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Lexikos



Joined: 17 Oct 2006
Posts: 2602
Location: Australia, Qld

PostPosted: Thu Apr 12, 2007 6:50 am    Post subject: ControlGet, ..., Line, N returns "error" for empty Reply with quote

I found a minor gotcha (which seems like a bug to me) with ControlGet and text boxes.

When getting a line of text from an Edit control (in Notepad) using:
Code:
ControlGet, ..., Line, N, ...

ErrorLevel is set to 1 (indiciating an error occurred) when line N is empty.

To reproduce this, I used:
Code:
^#t::
    ControlGet, line, CurrentLine,       , Edit1, A
    ControlGet, line, Line       , %line%, Edit1, A
    MsgBox text: %line%`nErrorLevel: %ErrorLevel%
return

Pressing ^#t when the cursor is on a line with text shows a messagebox with:
Code:
text: The quick brown fox jumped over the lazy dog.
ErrorLevel: 0

while pressing ^#t when the cursor is on an empty line shows:
Code:
text:
ErrorLevel: 1

If the control does not exist (i.e. notepad is not active):
Code:
text:
ErrorLevel: 1

...as expected (and documented.)

If it is not possible to differentiate between:
  • An error in retrieving the text.
  • Retrieving an empty line of text.
... I suggest a note of this be made in the documentation.

AHK version: 1.0.46.10
OS: Windows XP w/ SP2
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Apr 12, 2007 2:38 pm    Post subject: Reply with quote

I've checked MSDN and it appears that the EM_GETLINE message (which is what is used internally for this) doesn't provide any way to distinguish between an empty line and one that doesn't exist. Therefore, I've documented it: "If the specified line number is blank or does not exist, ErrorLevel is set to 1 and OutputVar is made blank."

The script can use "ControlGet LineCount" to find out whether a particular line number exists. In fact, AutoHotkey could be changed to do this internally, but it doesn't seem worth breaking existing scripts.

Thanks.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group