Sign in to follow this  
Followers 0
comradeb14ck

Problem with GUICtrlRead()

2 posts in this topic

Hi everyone.

I'm having a quite odd problem here. I've pasted my code below. What I have is a small GUI application which has 3 input boxes (GUICtrlCreateInput). The user enters 3 numbers into these boxes, and I use GUICtrlRead() to read the numbers out of those input boxes into a variable called delay. Then to handle the number as a number (not as textual input), I use the Number() function to convert the user's input into a number.

The first 2 input boxes work fine in my program, but the last box which reads in $charmovedelay, ONLY works properly the first time that the program is started, after that it no longer works and always thinks the user inputted a value of 0, even if that is not the case.

I am thinking this may be a bug in the AU3 engine, but if I'm wrong, please do correct me! I've been looking at this for quite a long time and cannot seem to figure it out. Thanks.

#include <GUIConstants.au3>

$WIDTH = 500
$HEIGHT = 680
$LINE_HEIGHT = 20

$gui = GUICreate ("debug", $WIDTH, $HEIGHT)
GUISetBkColor (0x222222)

$startstop_button = GUICtrlCreateButton ("Start / Stop Button", 200, 80, 125, 25)
$castdelay = GUICtrlCreateInput ( "", 10, 20, 50, $LINE_HEIGHT)
$keydowndelay = GUICtrlCreateInput ( "", 10, 40, 50, $LINE_HEIGHT)
$charmovedelay = GUICtrlCreateInput ( "", 10, 60, 50, $LINE_HEIGHT)

GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg ()
        
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $startstop_button
            $delay = GUICtrlRead ($castdelay)
            MsgBox(0,"DEBUG1","Number($delay)="&Number($delay))
            If $delay = "" Or Number ($delay) <= 0 Then
                $delay = 1000
            Else
                $delay = Number ($delay)
            EndIf
            AutoItSetOption ("SendKeyDelay", $delay)
            
            $delay = GUICtrlRead ($keydowndelay)
            MsgBox(0,"DEBUG2","Number($delay)="&Number($delay))
            If $delay = "" Or Number ($delay) <= 0 Then
                $delay = 5
            Else
                $delay = Number ($delay)
            EndIf
            AutoItSetOption ("SendKeyDownDelay", $delay)
            
        ; BUGGED ============
            $delay = GUICtrlRead ($charmovedelay)
            MsgBox(0,"DEBUG3","Number($delay)="&Number($delay))
            If $delay = "" Or Number ($delay) <= 60000 Then
                $delay = 300000
            Else
                $delay = Number ($delay)
            EndIf
            $charmovedelay = $delay
        ; BUGGED ============
            
    EndSelect
WEnd

To test out what I mean, run the code, and enter in values into all 3 input boxes (numerical values). Then press the start button. It will print 3 messages with the numerical values for each of the inputs. Now, try to modify each of the 3 inputs and press the start button again. It *should* re-read the values in the boxes and print them correctly, but it doesnt work like that on the last box. Help please!

Thanks again.

Share this post


Link to post
Share on other sites



This line

$charmovedelay = $delay

is destroying the handle to the 3rd input control, so the 2nd time round, GuiCtrlRead attempts to read a number (id) not same as before and since it does not exist, I suppose it returns 0 instead of what you expect.

:)

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