 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Lexikos
Joined: 17 Oct 2006 Posts: 2602 Location: Australia, Qld
|
Posted: Thu Apr 12, 2007 6:50 am Post subject: ControlGet, ..., Line, N returns "error" for empty |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Apr 12, 2007 2:38 pm Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|