Jump to content
Sign in to follow this  
blipton

GUICtrlRead isn't reading the data from array of Input Controls

Recommended Posts

I;m creating 10 TextBoxes, and saving the IDs in an array

; Create and Populate Defaults
        For $i = 0 To 9
            $cCID[$i] = GUICtrlCreateInput("XXXX", 10, 10 + (20 * $i), 45, 20)    
            GUICtrlSetData($cCID[$i], "0x" & Hex($i, 4))
        Next

This works correctly, and displays 10 textboxes with incrementing values starting at 0x0000 and ending with 0x0009. 

But reading from these textboxes, using the same scheme, always returns 0:

$Checksum = 0
        For $i = 0 To 9 Step 1
            $Checksum += GUICtrlRead( $cCID[$i] )
        Next

I'm assuming the ID is not correct, but not sure why not.. it works when addressing to set the value?

Share this post


Link to post
Share on other sites

It works fine for me, returns result of 45

#include <GUIConstantsEx.au3>
Example()
Func Example()
    Local $cCID[10]
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    For $i = 0 To 9
        $cCID[$i] = GUICtrlCreateInput("XXXX", 10, 10 + (20 * $i), 45, 20)
        GUICtrlSetData($cCID[$i], "0x" & Hex($i, 4))
    Next
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOK
                Local $Checksum = ""
                For $i = 0 To 9
                    $Checksum += GUICtrlRead( $cCID[$i] )
                Next
                MsgBox(4096, "Total", $Checksum)
        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Edited by Subz

Share this post


Link to post
Share on other sites

I don't get it.. putting it in it's own function works.   I don't see why it doesn't work as-is for me.   Would you mind seeing if this works for you?   

I'm running AutoIt v3 (not sure what sub-build) on a Win8x64 machine.   Is it possible it's a bug in AutoIt?  

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Checksum Calc",       250, 600,  100, 25)
$Button1 = GUICtrlCreateButton("Calculate", 110,  64,  65,  41)
$Label1  = GUICtrlCreateLabel("Checksum: ",  90, 112,  100, 20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; DEFAULTS
Global $arr[10] = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Global $cCID [10]

; Create and Populate Defaults
For $i = 0 To 9
    $cCID[$i] = GUICtrlCreateInput("XXXX", 10, 10 + (20 * $i), 45, 20)   ;45 is width
    GUICtrlSetData($cCID[$i], "0x" & Hex($arr[$i], 4))
Next

; Init Checksum Label
GUICtrlSetData($Label1,  "Checksum: 0xXXXX"  )

; GUI Handling
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

      Case $GUI_EVENT_CLOSE
          Exit

      Case $Button1
          ;Calculate Checksum!
          $Checksum = 0
          For $i = 0 To 9 Step 1
            $Checksum += GUICtrlRead( $cCID[$i] )
            ConsoleWrite(Hex($Checksum,4)&@CRLF)   ;DEBUG
          Next

          ; Print Checksum
          GUICtrlSetData($Label1,  "Checksum: 0x" & Hex( $Checksum , 4 ) )

        EndSwitch
WEnd

 

 

Share this post


Link to post
Share on other sites

Your loop computing the checksum should be:

For $i = 0 To 9
            $Checksum += Int(GUICtrlRead($cCID[$i]))
;~             ConsoleWrite(Hex($Checksum, 4) & @CRLF)   ;DEBUG
          Next

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

That fixed it, thanks!    Just curious, how do you know when the (Int) needed?    The code from Subz, without the (Int), works fine and it looks the same to me.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...