Sign in to follow this  
Followers 0
James

10x10 Grid in GUI

31 posts in this topic




Grid of what? Just unclickable words? That sounds weird.

Share this post


Link to post
Share on other sites

No.. A grid that looks like:

Posted Image

That will go into a GUI. I can then hold my mouse down and select multiple squares. The program will read the selected numbers. Get both 4 numbers from the corner and store them to an array.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#include <GUIconstants.au3>
GUICreate("")
Dim $Aij[11][11]
$separ1=10
$separ2=10
$n=1
For $i=1 to 10
    For $a=1 to 10
        $Aij[$i][$a] = GUICtrlCreateInput($n, $separ1, $separ2, 33, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY), $WS_EX_STATICEDGE)
        $separ1 = $separ1+34
        if $a = 10 Then
            $separ1=10
        EndIf
        $n+=1
    Next
$separ2=$separ2+22
Next
GUISetState(@SW_SHOW)
While 1
    Sleep(100)
WEnd

?

Edited by Nahuel

Share this post


Link to post
Share on other sites

Hey all,

I am trying to make a 10x10 grid with the numbers:

1 2 3 4 5 6 7 8 9 10

11 12 13 14 15 16 17 18 19 20

etc

Anyone know how?

Thanks,

James

If you want 10 x 10 buttons numbered 1 -100:

#include <GUIConstants.au3>

GUICreate("My GUI", 440, 440)  ; will create a dialog box that when displayed is centered
GUISetState (@SW_SHOW)       ; will display an empty dialog box

Dim $btnArray[100]

$num = 0
For $Y = 0 to 9
    For $X = 0 to 9
        $btnArray[$num] = GUICtrlCreateButton ( $num + 1, ($X * 40) + 20, ($Y * 40) + 20, 40, 40)
        $num += 1
    Next
Next


; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $btnArray[0]
            ;Do stuff
        Case $btnArray[1]
            ;Do other stuff....

    EndSwitch
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You could do this but you would have to have a case statement for each array element:

#include <GUIConstants.au3>

GUICreate("My GUI", 440, 440)  ; will create a dialog box that when displayed is centered
GUISetState (@SW_SHOW)       ; will display an empty dialog box

Dim $btnArray[100][2]

$num = 0
For $Y = 0 to 9
    For $X = 0 to 9
        $btnArray[$num][0] = GUICtrlCreateButton ( $num + 1, ($X * 40) + 20, ($Y * 40) + 20, 40, 40)
        $num += 1
    Next
Next

Func toggle($element)
    ;If already hilighted
    If $btnArray[$element][1] = true Then
        ;Reset to default
        GUICtrlSetBkColor ($btnArray[$element][0], 0xFFFFFF)
        $btnArray[$element][1] = false
    Else
        GUICtrlSetBkColor ($btnArray[$element][0], 0x505050)
        $btnArray[$element][1] = true
    EndIf
    
EndFunc

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $btnArray[0][0]
             toggle(0)
        Case $btnArray[1][0]
             toggle(1)
        Case $btnArray[2][0]
             toggle(2)

    EndSwitch
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

If anyone knows a way to handle messages from this many buttons, let me know.

Edited by weaponx

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Genious. Just need to toggle back when its clicked again. How could I store the buttons pressed to an array, then get the far top right and left and far bottom right and left numbers?

Edit: @weaponx, I am sure you could do a For Statement to check the button pressed, but I dont know how..

Edited by JamesB

Share this post


Link to post
Share on other sites

I'm getting ready to leave work now, I should be able to look at this in about 30 mins. I have the toggle function in there but setting the color back to default makes the button "flat".

P.S. It is easy to get the corner buttons they are elements [0], [9], [90], and [99]

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

GUICreate("My GUI", 440, 440)  ; will create a dialog box that when displayed is centered
GUISetState(@SW_SHOW)       ; will display an empty dialog box

Dim $btnArray[100][2]
Dim $add = 0
$num = 0
For $Y = 0 To 9
    For $X = 0 To 9
        $btnArray[$num][0] = GUICtrlCreateButton($num + 1, ($X * 40) + 20, ($Y * 40) + 20, 40, 40)
        GUICtrlSetBkColor($btnArray[$num][0], 0xFFFFFF)
        $num += 1
    Next
Next

$reset = GUICtrlCreateButton("reset", 150, 420, 40, 20)
$label = GUICtrlCreateLabel("Total = 0", 200, 422, 80, 20)


; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $reset Then
        For $X = 0 To 99
            $btnArray[$X][1] = True
            toggle($X)
        Next
        $add = 0
        GUICtrlSetData($label, "Total = 0")
    EndIf
    
    For $X = 0 To 99
        If $msg = $btnArray[$X][0] Then
            toggle($X)
        EndIf
    Next

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func toggle($element)
    ;If already hilighted
    If $btnArray[$element][1] = True Then
        ;Reset to default
        GUICtrlSetBkColor($btnArray[$element][0], 0xFFFFFF)
        $btnArray[$element][1] = False
        $add = ($add - ($element + 1))
        GUICtrlSetData($label, "Total = " & $add)
    Else
        GUICtrlSetBkColor($btnArray[$element][0], 0x505050)
        $btnArray[$element][1] = True
        $add = $add + ($element + 1)
        GUICtrlSetData($label, "Total = " & $add)
    EndIf

EndFunc   ;==>toggle

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks Val, unfortunatley some of the buttons don't always click <_< and, the algrothim for working out the difference is wrong, but I think I can fix that.

You get the top far left corner number and the bottom far right number, times then together then you get the, bottom far left number and times that together, you then take the smallest number away from the biggest number and thats the difference.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Thanks to Val, I have got the following:

; Number Grid
; James Brooks
; Calculates difference
;       between numbers selected in grid

#include <GUIConstants.au3>

Global $aDif
Dim $btnArray[100][2]

GUICreate("Number Grid - James Brooks - Maths C/W Assistant", 440, 500)
GUICtrlCreateLabel("Maths C/W Assistant: Click multiple buttons to work out the difference!", 50, 5)
GUICtrlCreateLabel("Algebra Equation:", 10, 440)
$Equation = GUICtrlCreateInput("", 100, 438, 325)
$Difference = GUICtrlCreateLabel("Difference: " & $aDif, 10, 460, 100, 16)
$reset = GUICtrlCreateButton("reset", 150, 420, 40, 20)
GUISetState(@SW_SHOW)

$num = 0
For $Y = 0 To 9
    For $X = 0 To 9
        $btnArray[$num][0] = GUICtrlCreateButton($num + 1, ($X * 40) + 20, ($Y * 40) + 20, 40, 40)
        $num += 1
    Next
Next

While 1
    $msg = GUIGetMsg()
    If $msg = $reset Then
        For $X = 0 To 99
            $btnArray[$X][1] = True
            toggle($X)
        Next
        $add = 0
        GUICtrlSetData($Difference, "Difference = 0")
    EndIf

    For $X = 0 To 99
        If $msg = $btnArray[$X][0] Then
            toggle($X)
        EndIf
    Next

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func toggle($element)
    ;If already hilighted
    If $btnArray[$element][1] = True Then
        ;Reset to default
        GUICtrlSetBkColor($btnArray[$element][0], 0xFFFFFF)
        $btnArray[$element][1] = False
        $add = ($add - ($element + 1))
        GUICtrlSetData($Difference, "Difference = " & $add)
    Else
        GUICtrlSetBkColor($btnArray[$element][0], 0x505050)
        $btnArray[$element][1] = True
        $add = $add + ($element + 1)
        GUICtrlSetData($Difference, "Difference = " & $add)
    EndIf
EndFunc   ;==>toggle

Problems:

  • Click four buttons, the last button wont unclick
  • The equation is wrong (How do I get the corner numbers?)
  • Buttons are flat after being clicked - Looks good like that!
-James

P.S: Thanks for all the help so far guys!

Edited by JamesB

Share this post


Link to post
Share on other sites

Just loop through the array for all items set to true.

Share this post


Link to post
Share on other sites

Okay I got this working better in OnEventMode except there is a bug in 3.2.8.1 that fires an event twice on colored buttons. I'm working on a solution.

Share this post


Link to post
Share on other sites

Here is a cleaned up version, since i'm not ready for beta I chose to have a large font on selected buttons:

; Number Grid
; James Brooks
; Calculates difference
;      between numbers selected in grid

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 

;Global vars
Dim $aDif, $add
Dim $btnArray[100][2]

GUICreate("Number Grid - James Brooks - Maths C/W Assistant", 440, 500)
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlCreateLabel("Maths C/W Assistant: Click multiple buttons to work out the difference!", 50, 5)
GUICtrlCreateLabel("Algebra Equation:", 10, 440)
$Equation = GUICtrlCreateInput("", 100, 438, 325)
$Difference = GUICtrlCreateLabel("Difference: " & $aDif, 10, 460, 100, 16)
$reset = GUICtrlCreateButton("reset", 200, 470)
GUICtrlSetOnEvent(-1, "reset")

;Generate buttons 10x10 labeled 1-100
$num = 0
For $Y = 0 To 9
    For $X = 0 To 9
        $btnArray[$num][0] = GUICtrlCreateButton($num + 1, ($X * 40) + 20, ($Y * 40) + 20, 40, 40)
        GUICtrlSetOnEvent(-1, "buttonPress")
        GUICtrlSetFont (-1,9, default)
        $btnArray[$num][1] = false
        $num += 1
    Next
Next

While 1
  Sleep(10)  ; Idle around
WEnd

Func buttonPress()
    ;Loop through all buttons for match
    For $X = 0 To 99
        If @GUI_CTRLID = $btnArray[$X][0] Then
            toggle($X)
            Return
        EndIf
    Next
EndFunc

Func toggle($element)
    ;If button already selected, deselect it
    If $btnArray[$element][1] Then

        ;Reset to default color + style
        GUICtrlSetFont ($btnArray[$element][0],9, default)

        $btnArray[$element][1] = False
        $add = ($add - ($element + 1))
        GUICtrlSetData($Difference, "Difference = " & $add)
    Else

        ;Set background color to dark grey
        GUICtrlSetFont ($btnArray[$element][0],20, 600)

        $btnArray[$element][1] = True
        $add += ($element + 1)
        GUICtrlSetData($Difference, "Difference = " & $add)
    EndIf
EndFunc   ;==>toggle

Func reset()
    For $X = 0 To 99
        $btnArray[$X][1] = False
        GUICtrlSetFont ($btnArray[$X][0],9, default)
    Next
    $add = 0
    GUICtrlSetData($Difference, "Difference = 0")
EndFunc

Func CLOSEClicked()
    Exit
EndFunc

Now about selected the 4 corners...I don't understand how you want to do this...

What if only 3 buttons are selected?

What if the selected buttons are in a zig-zag pattern?

Share this post


Link to post
Share on other sites

Mmm. That's why I thought it was strange he'd just want unmodifiable numbers. I don't get what the point of the script is. Perhaps you should go with checkboxes w/ numbers next to them? I have no idea.

Share this post


Link to post
Share on other sites

Instructions for 10x10 Grid:

  • A box is drawn around 4 numbers
  • Find the product of the top left number and the bottom right number in this box
  • Do the same with the top right and bottom left numbers
  • Calculate the difference between these products
I need to be able to do that <_<

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