Sign in to follow this  
Followers 0
danny0

Help with for loop

9 posts in this topic

I have this really long script and I know it can be easily condensed into a for loop. I just don't know how. Can someone please put everything in a for loop and explain what is happening.

Script.au3

Share this post


Link to post
Share on other sites



I have this really long script and I know it can be easily condensed into a for loop. I just don't know how. Can someone please put everything in a for loop and explain what is happening.

yikes... I just ran that and you have overlapping controls and miss-matched edges all over the place. :)

Clean it up a little, and i will gladly condense it for you.

Share this post


Link to post
Share on other sites

holy hell

question time:

1. what is that supposed to be

2. what does it need to do

3. what should happen when it is doing what it needs to be

4. what is the overall objective of the layout

5. OMG o_O


Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites

holy hell

question time:

1. what is that supposed to be

2. what does it need to do

3. what should happen when it is doing what it needs to be

4. what is the overall objective of the layout

5. OMG o_O

1.) That is obvious. It's a Sudoku Board

The rest of your questions are irrelevant, as it is simply creating the board design, and not doing anything with actual mechanics at this point, so asking what it is supposed to do isn't applicable.

Share this post


Link to post
Share on other sites

yikes... I just ran that and you have overlapping controls and miss-matched edges all over the place. :)

Clean it up a little, and i will gladly condense it for you.

I think this should be good. Can you also explain to me what the for loop is doing so I can do this myself next time.

Script.au3

Share this post


Link to post
Share on other sites

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

$Form = GUICreate("Form", 600, 600); Centered, square window
$Button1 = GUICtrlCreateButton("Clear", 100, 550, 75, 25, 0)
$Button2 = GUICtrlCreateButton("AutoSolve", 250, 550, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Stop", 400, 550, 75, 25, 0)

Dim $Graphics[81], $index = 0 ;Define an array, creat a variable to increase
For $Column = 0 To 8 ; 9 Columns
    For $Row = 0 To 8; 9 Rows
        $Graphics[$index] = GUICtrlCreateGraphic(12 + (64 * $Column), 12 + (58 * $Row), 64, 58, $SS_SUNKEN)
        GUICtrlSetColor(-1, 0x000000)
        $index += 1
    Next
Next

Dim $Labels[81], $index = 0
For $Column = 0 To 8
    For $Row = 0 To 8
        $Labels[$index] = GUICtrlCreateLabel("", 30 + (64 * $Column), 18 + (58 * $Row), 30, 30, $SS_CENTER, $WS_EX_STATICEDGE)
        $index += 1
    Next
Next

Dim $Inputs[81], $index = 0
For $Column = 0 To 8
    For $Row = 0 To 8
        $Inputs[$index] = GUICtrlCreateInput("123456789", 16 + (64 * $Column), 50 + (58 * $Row), 55, 15, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_NUMBER), $WS_EX_STATICEDGE)
        GUICtrlSetFont(-1, 7, 400, 0, "Arial Narrow")
        $index += 1
    Next
Next

GUISetState(@SW_SHOW, $Form)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

There you are. script is shortened, now let me explain my logic:

Basically, i did some mathcraft and found the proper number to multiply each width and height by, and multiplied it by the column and row variables in the loop

That probably makes no sense, so if looking closely at the code doesn't help, i can come up with a simpler example that may make it easier to see

Share this post


Link to post
Share on other sites

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

$Form = GUICreate("Form", 600, 600); Centered, square window
$Button1 = GUICtrlCreateButton("Clear", 100, 550, 75, 25, 0)
$Button2 = GUICtrlCreateButton("AutoSolve", 250, 550, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Stop", 400, 550, 75, 25, 0)

Dim $Graphics[81], $index = 0 ;Define an array, creat a variable to increase
For $Column = 0 To 8 ; 9 Columns
    For $Row = 0 To 8; 9 Rows
        $Graphics[$index] = GUICtrlCreateGraphic(12 + (64 * $Column), 12 + (58 * $Row), 64, 58, $SS_SUNKEN)
        GUICtrlSetColor(-1, 0x000000)
        $index += 1
    Next
Next

Dim $Labels[81], $index = 0
For $Column = 0 To 8
    For $Row = 0 To 8
        $Labels[$index] = GUICtrlCreateLabel("", 30 + (64 * $Column), 18 + (58 * $Row), 30, 30, $SS_CENTER, $WS_EX_STATICEDGE)
        $index += 1
    Next
Next

Dim $Inputs[81], $index = 0
For $Column = 0 To 8
    For $Row = 0 To 8
        $Inputs[$index] = GUICtrlCreateInput("123456789", 16 + (64 * $Column), 50 + (58 * $Row), 55, 15, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_NUMBER), $WS_EX_STATICEDGE)
        GUICtrlSetFont(-1, 7, 400, 0, "Arial Narrow")
        $index += 1
    Next
Next

GUISetState(@SW_SHOW, $Form)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

There you are. script is shortened, now let me explain my logic:

Basically, i did some mathcraft and found the proper number to multiply each width and height by, and multiplied it by the column and row variables in the loop

That probably makes no sense, so if looking closely at the code doesn't help, i can come up with a simpler example that may make it easier to see

I get it. Thanks a bunch!

Share this post


Link to post
Share on other sites

I get it. Thanks a bunch!

Awesome! No problem, glad I could help. :)

I wish you luck on making a sudoku solver, I've tried myself and given up on the core logic several times. However, I'm sure there are examples on this forum that could perhaps help you along the way.

Share this post


Link to post
Share on other sites

Awesome! No problem, glad I could help. :)

I wish you luck on making a sudoku solver, I've tried myself and given up on the core logic several times. However, I'm sure there are examples on this forum that could perhaps help you along the way.

Some time ago, I saved the listing of a Sudoku solver, that I found on the forum of another programming language. I don't know if it is permitted to publish it here in AutoIt format?

If it is permitted, I will glad to post it.

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