Sign in to follow this  
Followers 0
atomman

Possible Bug: could relate to ControlCommand() or an Edit control

11 posts in this topic

#1 ·  Posted (edited)

I know there's a problem(s) with the edit control in 3.2.10, so i don't know if this is related to that or not.

Problem here is ControlCommand - "GetLineCount" not returning proper value.

UPDATE: substituting _GUICtrlEdit_GetLineCount() for ControlCommand() causes different behavior and *may* eliminate the problem, therefore reinforcing a problem with ControlCommand - "GetLineCount". More testing needed.

Make sure to read the comments.

"GetLineCount" works fine as this script is set up and will return correct values, so the first thing to do to reproduce the problem is comment out line #17:

ControlClick($Form1, "", $Edit1); ### if this IS commented out, then $a returns wrong value

I left other code in here that was used for testing.

#include <GUIConstants.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 245, 241, -1, -1)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 121, 240)
GUICtrlSetData(-1, StringFormat("1\r\n2\r\n3"))
;GUICtrlSetData(-1, StringFormat("1"))
$Edit2 = GUICtrlCreateEdit("", 123, 0, 121, 240, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL))
GUICtrlSetData(-1, StringFormat("1\r\n2\r\n3"))
GUISetState(@SW_SHOW)

;WinActivate($Form1)
;WinWaitActive($Form1)
ControlClick($Form1, "", $Edit1); ### if this IS commented out, then $a returns wrong value
$a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
;WinActivate($Form1)
;WinWaitActive($Form1)
;ControlClick($Form1, "", $Edit2); ### if this IS NOT commented out, then $b returns wrong value ###
$b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
MsgBox(0, "", "Edit1 has " & $a & " lines" & @CRLF & "Edit2 has " & $b & " lines")
;If $a <> $b Then
;MsgBox(0,"", "not equal")
    If $b < $a Then
        MsgBox(0, "", "1 > 2")
        Do
            _GUICtrlEdit_AppendText($Edit2, @CRLF & "adding line")
    ;ControlFocus($Form1, "", $Edit1)
    ;ControlClick($Form1, "", $Edit1)
            $a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
    ;ControlFocus($Form1, "", $Edit2)
    ;ControlClick($Form1, "", $Edit2)
            $b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
            Sleep(250)
        Until $b = $a
    ElseIf $a < $b Then
;MsgBox(0, "", "1 < 2")
        Do
            _GUICtrlEdit_AppendText($Edit1, @CRLF & "adding line")
    ;ControlFocus($Form1, "", $Edit2)
    ;ControlClick($Form1, "", $Edit2)
            $b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
    ;ControlFocus($Form1, "", $Edit1)
    ;ControlClick($Form1, "", $Edit1)
            $a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
            Sleep(250)
        Until $a = $b
    EndIf
;EndIf


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by atomman

Share this post


Link to post
Share on other sites



can someone confirm please?

Share this post


Link to post
Share on other sites

Bugs are usually placed in Bugs forum. Works fine here :)


I can do signature me.

Share this post


Link to post
Share on other sites

Works fine here :)

Did you uncomment/comment the 2 lines, one at a time, as specified? Because as the code is posted, yes, it will work fine.

I didn't post this in the bug forum yet because i needed to verify it first, and...

Before posting a bug report, [...]. Also, be sure the bug is really a bug. [...] Instead, post in support and let the veterans take a look at it and determine whether the problem is in your code or in AutoIt.

Let me know if you just ran the code as-is, or played with the 2 lines that have the comments after them.

Thanks!

Share this post


Link to post
Share on other sites

Did you uncomment/comment the 2 lines, one at a time, as specified? Because as the code is posted, yes, it will work fine.

I didn't post this in the bug forum yet because i needed to verify it first, and...

Let me know if you just ran the code as-is, or played with the 2 lines that have the comments after them.

Thanks!

I run code as-is once and played with comments. All ok.

I can do signature me.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Doesn't make sense to me. If i un-comment line 19, i can reproduce the error every time.

;ControlClick($Form1, "", $Edit2); ### if this IS NOT commented out, then $b returns wrong value ###

Here it is again, trimmed down, if anyone else wants to try it...

#include <GUIConstants.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 245, 241, -1, -1)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 121, 240)
GUICtrlSetData(-1, StringFormat("1\r\n2\r\n3"))
$Edit2 = GUICtrlCreateEdit("", 123, 0, 121, 240, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL))
GUICtrlSetData(-1, StringFormat("1\r\n2\r\n3"))
GUISetState(@SW_SHOW)

ControlClick($Form1, "", $Edit1); ### if this IS commented out, then $a returns wrong value
$a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
;ControlClick($Form1, "", $Edit2); ### if this IS NOT commented out, then $b returns wrong value ###
$b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
MsgBox(0, "", "Edit1 has " & $a & " lines" & @CRLF & "Edit2 has " & $b & " lines")
    If $b < $a Then
        MsgBox(0, "", "1 > 2")
        Do
            _GUICtrlEdit_AppendText($Edit2, @CRLF & "adding line")
            $b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
            Sleep(250)
        Until $b = $a
    ElseIf $a < $b Then
        Do
            _GUICtrlEdit_AppendText($Edit1, @CRLF & "adding line")
            $a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
            Sleep(250)
        Until $a = $b
    EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by atomman

Share this post


Link to post
Share on other sites

I was going to say try using control focus first but that makes things just as bad, it's then wrong for both lists

#include <GUIConstants.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 245, 241, -1, -1)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 121, 240)
GUICtrlSetData(-1, StringFormat("1\r\n2\r\n3"))
$Edit2 = GUICtrlCreateEdit("", 123, 0, 121, 240, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL))
GUICtrlSetData(-1, StringFormat("1\r\n2\r\n3"))
GUISetState(@SW_SHOW)

;ControlClick($Form1, "", $Edit1); ### if this IS commented out, then $a returns wrong value
ControlFocus($Form1, "", "Edit1")
$a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
;ControlClick($Form1, "", $Edit2); ### if this IS NOT commented out, then $b returns wrong value ###
ControlFocus($Form1, "", "Edit2")
$b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
MsgBox(0, "", "Edit1 has " & $a & " lines" & @CRLF & "Edit2 has " & $b & " lines")
    If $b < $a Then
        MsgBox(0, "", "1 > 2")
        Do
            _GUICtrlEdit_AppendText($Edit2, @CRLF & "adding line")
            $b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
            Sleep(250)
        Until $b = $a
    ElseIf $a < $b Then
        Do
            _GUICtrlEdit_AppendText($Edit1, @CRLF & "adding line")
            $a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
            Sleep(250)
        Until $a = $b
    EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

I was going to say try using control focus first but that makes things just as bad, it's then wrong for both lists

#include <GUIConstants.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 245, 241, -1, -1)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 121, 240)
GUICtrlSetData(-1, StringFormat("1\r\n2\r\n3"))
$Edit2 = GUICtrlCreateEdit("", 123, 0, 121, 240, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL))
GUICtrlSetData(-1, StringFormat("1\r\n2\r\n3"))
GUISetState(@SW_SHOW)

;ControlClick($Form1, "", $Edit1); ### if this IS commented out, then $a returns wrong value
ControlFocus($Form1, "", "Edit1")
$a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
;ControlClick($Form1, "", $Edit2); ### if this IS NOT commented out, then $b returns wrong value ###
ControlFocus($Form1, "", "Edit2")
$b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
MsgBox(0, "", "Edit1 has " & $a & " lines" & @CRLF & "Edit2 has " & $b & " lines")
    If $b < $a Then
        MsgBox(0, "", "1 > 2")
        Do
            _GUICtrlEdit_AppendText($Edit2, @CRLF & "adding line")
            $b = ControlCommand($Form1, "", "Edit2", "GetLineCount")
            Sleep(250)
        Until $b = $a
    ElseIf $a < $b Then
        Do
            _GUICtrlEdit_AppendText($Edit1, @CRLF & "adding line")
            $a = ControlCommand($Form1, "", "Edit1", "GetLineCount")
            Sleep(250)
        Until $a = $b
    EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

I can confirm that ControlCommand("Form1", "", $Edit1, "GetLineCount","") is not returning the count of the number of lines in the edit control it is in fact returning the line number of the line containing the caret. I have submitted a bug report for this.

Script to demonstrate problem

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 245, 241, -1, -1)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 121, 240)
GUICtrlSetData(-1, "1" & @CRLF & "2" & @CRLF & "3" & @CRLF & "4" & @CRLF & "5")
GUISetState(@SW_SHOW)

WinActivate("Form1")
WinWaitActive("Form1")
For $i = 1 To 5
    sleep(2000)
    $a = ControlCommand("Form1", "", $Edit1, "GetLineCount","")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $a = ' & $a & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Send("{UP}")
Next
For $i = 1 To 5
    sleep(2000)
    $a = ControlCommand("Form1", "", $Edit1, "GetLineCount","")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $a = ' & $a & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Send("{DOWN}")
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Hi Chris.

Thanks for the tip, but i'm not actually looking for a solution to a problem (did that already). I just want someone more knowledgeable than i to verify this as a possible bug, which i believe it is, before posting in the bug forums.

There are 2 ControlClick functions used, and i would think they should act identically but that is not the case. The only way the correct values are returned is if one is commented out as above. As soon as you un-comment the second, the wrong value is returned for $b.

Would you agree on a possible bug here?

Share this post


Link to post
Share on other sites

Hi Chris.

Thanks for the tip, but i'm not actually looking for a solution to a problem (did that already). I just want someone more knowledgeable than i to verify this as a possible bug, which i believe it is, before posting in the bug forums.

There are 2 ControlClick functions used, and i would think they should act identically but that is not the case. The only way the correct values are returned is if one is commented out as above. As soon as you un-comment the second, the wrong value is returned for $b.

Would you agree on a possible bug here?

I got told a while ago that I should use use controlfocus before using control(somethingelse)

I had a script a while ago which was an on-screen keyboard where I had an issue with a control Function and I was told to use controlfocus first.

I'm pretty sure it was Larry who told me and at the time was one of the Devs which was why I was thinking you need to use controlFocus() however yes I agree it does seem like a bug but I guess you'll need one of the Devs to confirm it isn't something else silly.

Does this happen on an external GUI or only on an autoit generated Gui. What happens if you write 2 scripts, one which generates a GUI and another to count the lines.

I know this is not what you want to do but my line of thouht is that maybe it is because the same script is accessing it's own GUI and that you should be using a GuiCtrlSomething internal gui function to get the data. Rather than ControlCommand which is generally for external applications.

Share this post


Link to post
Share on other sites

Chris, i tried everything i knew of and still got bad return values. I thought i left ControlFocus commented out in my first post to show that i tried it, but i didn't. The problem was solved long ago, but i wanted the dev's to be aware of a possible bug, if in fact it is.

BowMore - thanks for the confirmation and subsequent bug report.

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