James Posted October 29, 2007 Share Posted October 29, 2007 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 Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Nevin Posted October 29, 2007 Share Posted October 29, 2007 Grid of what? Just unclickable words? That sounds weird. Link to comment Share on other sites More sharing options...
James Posted October 29, 2007 Author Share Posted October 29, 2007 No.. A grid that looks like: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. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Nahuel Posted October 29, 2007 Share Posted October 29, 2007 (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 October 29, 2007 by Nahuel Link to comment Share on other sites More sharing options...
weaponx Posted October 29, 2007 Share Posted October 29, 2007 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 Link to comment Share on other sites More sharing options...
James Posted October 29, 2007 Author Share Posted October 29, 2007 Thanks weaponx and Nahuel. Is there anyway of changing the button colour once it has been clicked and storing the button number clicked? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted October 29, 2007 Share Posted October 29, 2007 (edited) You could do this but you would have to have a case statement for each array element: expandcollapse popup#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 October 29, 2007 by weaponx Link to comment Share on other sites More sharing options...
James Posted October 29, 2007 Author Share Posted October 29, 2007 (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 October 29, 2007 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted October 29, 2007 Share Posted October 29, 2007 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] Link to comment Share on other sites More sharing options...
James Posted October 29, 2007 Author Share Posted October 29, 2007 Ok, no I didn't mean to get the corner of the table, but the selected boxes. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Valuater Posted October 29, 2007 Share Posted October 29, 2007 expandcollapse popup#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) Link to comment Share on other sites More sharing options...
James Posted October 29, 2007 Author Share Posted October 29, 2007 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. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted October 29, 2007 Author Share Posted October 29, 2007 (edited) Thanks to Val, I have got the following:expandcollapse popup; 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 ;==>toggleProblems:Click four buttons, the last button wont unclickThe equation is wrong (How do I get the corner numbers?)Buttons are flat after being clicked - Looks good like that!-JamesP.S: Thanks for all the help so far guys! Edited October 29, 2007 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted October 29, 2007 Author Share Posted October 29, 2007 @weaponx, is there away of returning all of the selected boxes? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted October 29, 2007 Share Posted October 29, 2007 Just loop through the array for all items set to true. Link to comment Share on other sites More sharing options...
weaponx Posted October 29, 2007 Share Posted October 29, 2007 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. Link to comment Share on other sites More sharing options...
weaponx Posted October 29, 2007 Share Posted October 29, 2007 Here is a cleaned up version, since i'm not ready for beta I chose to have a large font on selected buttons: expandcollapse popup; 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? Link to comment Share on other sites More sharing options...
Nevin Posted October 29, 2007 Share Posted October 29, 2007 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. Link to comment Share on other sites More sharing options...
James Posted October 30, 2007 Author Share Posted October 30, 2007 Thanks weaponx, its working nice now! I will explain number grids later, when I get back from college Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted October 30, 2007 Author Share Posted October 30, 2007 Instructions for 10x10 Grid:A box is drawn around 4 numbersFind the product of the top left number and the bottom right number in this boxDo the same with the top right and bottom left numbersCalculate the difference between these productsI need to be able to do that Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now