Sign in to follow this  
Followers 0
redjester45

Grade my GUI homework please.

9 posts in this topic

Alrighty. I made a GUI with 24 buttons. Each button corresponds to another script I converted to an .EXE. It is working the way I want it to but seeing as how this is my first GUI I made, I was wondering if some of the more experienced AutoIT coders can give me any advice on any tips/comments or how they might have gone about doing it. Like I said earlier its working the way I want it to, just want to get some advice on what I could have done differently. I spent a lot of time cruising the help file so I figured it was time for some human advice.

Thank you in advance.

[/code]#include <GUIConstants.au3>

GUICreate("Select Script to Run") 

Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("NW-SE3k",  10, 30, 86)
$Button_2 = GUICtrlCreateButton ( "NW-SE5k",  0, -1)
$Button_3 = GUICtrlCreateButton ("DualNW-SE3k", 0, -1)
$Button_4 = GUICtrlCreateButton  ( "DualNW-SE5k" , 0, -1)
$Button_5 = GUICtrlCreateButton  ( "NE-SW3k" , -344, 30, 86)
$Button_6 = GUICtrlCreateButton  ( "NE-SW5k", 0, -1)
$Button_7 = GUICtrlCreateButton  ( "DualNE-SW3k", 0, -1)
$Button_8 = GUICtrlCreateButton  ( "DualNE-SW5k", 0, -1)
$Button_9 = GUICtrlCreateButton  ( "N-S3k" , -344, 30, 86)
$Button_10 = GUICtrlCreateButton ( "N-S5k", 0, -1)
$Button_11 = GUICtrlCreateButton  ( "DualN-S3k", 0, -1)
$Button_12 = GUICtrlCreateButton  ( "DualN-S5k", 0, -1)
$Button_13 = GUICtrlCreateButton ( "SE-NW3k", -344, 30, 86)
$Button_14 = GUICtrlCreateButton  ( "SE-NW5k", 0, -1)
$Button_15 = GUICtrlCreateButton  ( "DualSE-NW3k", 0, -1)
$Button_16 = GUICtrlCreateButton  ( "DualSE-NW5k", 0, -1)
$Button_17 = GUICtrlCreateButton  ( "S-N3k", -344, 30, 86)
$Button_18 = GUICtrlCreateButton  ( "S-N5k", 0, -1)
$Button_19 = GUICtrlCreateButton  ( "DualS-N3k", 0, -1)
$Button_20 = GUICtrlCreateButton  ( "DualS-N5k", 0, -1)
$Button_21 = GUICtrlCreateButton  ( "SW-NE3k", -344, 30, 86)
$Button_22 = GUICtrlCreateButton  ( "SW-NE5k", 0, -1)
$Button_23 = GUICtrlCreateButton  ( "DualSW-NE3k", 0, -1)
$Button_24 = GUICtrlCreateButton  ( "DualSW-NE5k", 0, -1)


GUISetState ()    


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            Run('C:\Documents and Settings\zero\Desktop\Script\NW-SE3K.exe')    
        Case $msg = $Button_2
            Run('C:\Documents and Settings\zero\Desktop\Script\NW-SE5K.exe') 
        Case $msg = $Button_3
            Run('C:\Documents and Settings\zero\Desktop\Script\DualNW-SE3K.exe')
        Case $msg = $Button_4
            Run('C:\Documents and Settings\zero\Desktop\Script\DualNW-SE5K.exe')
        Case $msg = $Button_5
            Run('C:\Documents and Settings\zero\Desktop\Script\NE-SW3K.exe')
        Case $msg = $Button_6
            Run('C:\Documents and Settings\zero\Desktop\Script\NE-SW5K.exe')
        Case $msg = $Button_7
            Run('C:\Documents and Settings\zero\Desktop\Script\DualNE-SW3K.exe')
        Case $msg = $Button_8
            Run('C:\Documents and Settings\zero\Desktop\Script\DualNE-SW5K.exe')
        Case $msg = $Button_9
            Run('C:\Documents and Settings\zero\Desktop\Script\N-S3K.exe')
        Case $msg = $Button_10
            Run('C:\Documents and Settings\zero\Desktop\Script\N-S5K.exe')
        Case $msg = $Button_11
            Run('C:\Documents and Settings\zero\Desktop\Script\DualN-S3K.exe')
        Case $msg = $Button_12
            Run('C:\Documents and Settings\zero\Desktop\Script\DualN-S5K.exe')
        Case $msg = $Button_13
            Run('C:\Documents and Settings\zero\Desktop\Script\SE-NW3K.exe')
        Case $msg = $Button_14
            Run('C:\Documents and Settings\zero\Desktop\Script\SE-NW5K.exe')
        Case $msg = $Button_15
            Run('C:\Documents and Settings\zero\Desktop\Script\DualSE-NW3K.exe')
        Case $msg = $Button_16
            Run('C:\Documents and Settings\zero\Desktop\Script\DualSE-NW5K.exe')
        Case $msg = $Button_17
            Run('C:\Documents and Settings\zero\Desktop\Script\S-N3K.exe')
        Case $msg = $Button_18
            Run('C:\Documents and Settings\zero\Desktop\Script\S-N5K.exe')
        Case $msg = $Button_19
            Run('C:\Documents and Settings\zero\Desktop\Script\DualS-N3K.exe')
        Case $msg = $Button_20
            Run('C:\Documents and Settings\zero\Desktop\Script\DualS-N5K.exe')
        Case $msg = $Button_21
            Run('C:\Documents and Settings\zero\Desktop\Script\SW-NE3K.exe')
        Case $msg = $Button_22
            Run('C:\Documents and Settings\zero\Desktop\Script\SW-NE5K.exe')
        Case $msg = $Button_23
            Run('C:\Documents and Settings\zero\Desktop\Script\DualSW-NE3K.exe')
        Case $msg = $Button_24
            Run('C:\Documents and Settings\zero\Desktop\Script\DualSW-NE5K.exe')
    EndSelect
Wend

[code]

Share this post


Link to post
Share on other sites



With a little more study, you'll be able to do the same thing in 10 lines or so.


Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

and how exactly would you suggest that Fossil Rock?? I think I'm having a problem related to the way you're inferring about how to make his script much more efficient. Are you talking about working with arrays and loops for how he can shorten his code lines??? And if so... when he's looping through his array of the buttons, how would he assign those values to variables to he could check the status of them to perform action on them?


My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


Link to post
Share on other sites

and how exactly would you suggest that Fossil Rock?? I think I'm having a problem related to the way you're inferring about how to make his script much more efficient. Are you talking about working with arrays and loops for how he can shorten his code lines??? And if so... when he's looping through his array of the buttons, how would he assign those values to variables to he could check the status of them to perform action on them?

Sounds to me like you already know what I'm going to say. Put all the names and coordinates into an array and build them with a loop. Then loop through the buttons checking to see if one has been clicked.

NOTE: Turned out to be a little over 20 lines.

#include <GUIConstants.au3>

Global Const $bScript[24][5] = [["NW-SE3k", 32, 22, 90, 25],["NW-SE5k", 32, 50, 90, 25],["DualNW-SE3k", 32, 77, 90, 25],["DualNW-SE5k", 32, 105, 90, 25] _ 
                            ,["NE-SW3k", 32, 133, 90, 25],["NE-SW5k", 32, 161, 90, 25],["DualNE-SW3k", 32, 188, 90, 25],["DualNE-SW5k", 32, 216, 90, 25] _ 
                            ,["N-S3k", 32, 244, 90, 25],["N-S5k", 32, 272, 90, 25],["DualN-S3k", 32, 299, 90, 25],["DualN-S5k", 32, 327, 90, 25] _ 
                            ,["SE-NW3k", 132, 22, 90, 25],["SE-NW5k", 132, 50, 90, 25],["DualSE-NW3k", 132, 77, 90, 25],["DualSE-NW5k", 132, 105, 90, 25] _ 
                            ,["S-N3k", 132, 133, 90, 25],["S-N5k", 132, 161, 90, 25],["DualS-N3k", 132, 188, 90, 25],["DualS-N5k", 132, 216, 90, 25] _ 
                            ,["SW-NE3k", 132, 244, 90, 25],["SW-NE5k", 132, 272, 90, 25],["DualSW-NE3k", 132, 299, 90, 25],["DualSW-NE5k", 132, 327, 90, 25]]
Dim $Button[24]
$GUI = GUICreate("Select Script to Run", 257, 377, -1, -1)

For $bMaker = 0 to UBound($bScript) -1
    $Button[$bMaker] = GUICtrlCreateButton($bScript[$bMaker][0], $bScript[$bMaker][1], $bScript[$bMaker][2], $bScript[$bMaker][3], $bScript[$bMaker][4])
Next
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect

For $i = 0 To UBound($bScript) -1 
    If $nMsg = $Button[$i] Then 
        MsgBox(0,"Run Script...", $bScript[$i][0] & ".exe"); <<<< Comment out if not needed.
;       Run("C:\Documents and Settings\zero\Desktop\Script\" & $bScript[$i][0] & ".exe"); <<<< Runs script.
EndIf
Next

Wend

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

and how exactly would you suggest that Fossil Rock?? I think I'm having a problem related to the way you're inferring about how to make his script much more efficient. Are you talking about working with arrays and loops for how he can shorten his code lines??? And if so... when he's looping through his array of the buttons, how would he assign those values to variables to he could check the status of them to perform action on them?

oO

create a 2-dimensional array with the buttons, program names and additional info, loop through it to create the button, in the message loop, just loop again and again loop throught the button-array to check which button sent the msg, use the program names for button labels as well as the "run program"-part...

edit: lol 2 late

edit2: fossil, why didn't you put the button infos and button handles into one array?

#include <GUIConstants.au3>

Global Const $bScript[24][6] = [["NW-SE3k", 32, 22, 90, 25, 0],["NW-SE5k", 32, 50, 90, 25, 0],["DualNW-SE3k", 32, 77, 90, 25, 0],["DualNW-SE5k", 32, 105, 90, 25, 0] _ 
                            ,["NE-SW3k", 32, 133, 90, 25, 0],["NE-SW5k", 32, 161, 90, 25, 0],["DualNE-SW3k", 32, 188, 90, 25, 0],["DualNE-SW5k", 32, 216, 90, 25, 0] _ 
                            ,["N-S3k", 32, 244, 90, 25, 0],["N-S5k", 32, 272, 90, 25, 0],["DualN-S3k", 32, 299, 90, 25, 0],["DualN-S5k", 32, 327, 90, 25, 0] _ 
                            ,["SE-NW3k", 132, 22, 90, 25, 0],["SE-NW5k", 132, 50, 90, 25, 0],["DualSE-NW3k", 132, 77, 90, 25, 0],["DualSE-NW5k", 132, 105, 90, 25, 0] _ 
                            ,["S-N3k", 132, 133, 90, 25, 0],["S-N5k", 132, 161, 90, 25, 0],["DualS-N3k", 132, 188, 90, 25, 0],["DualS-N5k", 132, 216, 90, 25, 0] _ 
                            ,["SW-NE3k", 132, 244, 90, 25, 0],["SW-NE5k", 132, 272, 90, 25, 0],["DualSW-NE3k", 132, 299, 90, 25, 0],["DualSW-NE5k", 132, 327, 90, 25, 0]]
$GUI = GUICreate("Select Script to Run", 257, 377, -1, -1)

For $bMaker = 0 to UBound($bScript) -1
   $bScript[$bMaker][5] = GUICtrlCreateButton($bScript[$bMaker][0], $bScript[$bMaker][1], $bScript[$bMaker][2], $bScript[$bMaker][3], $bScript[$bMaker][4])
Next
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect

For $i = 0 To UBound($bScript) -1 
    If $nMsg = $bScript[$i][5] Then 
        MsgBox(0,"Run Script...", $bScript[$i][0] & ".exe"); <<<< Comment out if not needed.
;      Run("C:\Documents and Settings\zero\Desktop\Script\" & $bScript[$i][0] & ".exe"); <<<< Runs script.
EndIf
Next

Wend
Edited by pixartist

Share this post


Link to post
Share on other sites

oO

create a 2-dimensional array with the buttons, program names and additional info, loop through it to create the button, in the message loop, just loop again and again loop throught the button-array to check which button sent the msg, use the program names for button labels as well as the "run program"-part...

edit: lol 2 late

edit2: fossil, why didn't you put the button infos and button handles into one array?

You so smart .... :)

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

You so smart .... :)

Muahah xD

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks for the advice and stuff. I tried to run pixartist and Fossil Rock's script but am encountering an error with the Au3Check:

C:\Documents and Settings\zero\Desktop\Scripts\test3.au3(12,156) : ERROR: $bScript previously declared as a 'Const'

$bScript[$bMaker][5] = GUICtrlCreateButton($bScript[$bMaker][0], $bScript[$bMaker][1], $bScript[$bMaker][2], $bScript[$bMaker][3], $bScript[$bMaker][4])

I think it might have something to do with assigning $bSctipt as a global constant. But since I am a noob I am really just kinda easter egging here. If you could let me know if I am on the right track of thinking that would be super. Oh yeah dont know if it makes a difference but I am using Win2KPro. Back to the Helpfile.

Edit: I got Fossil Rocks to run. But it is not running the .exe's. So I am still fiddling with it.

Edited by redjester45

Share this post


Link to post
Share on other sites

Hi, same thing but slightly different again..

#include <GUIConstants.au3>

Global $sPath = "C:\Documents and Settings\zero\Desktop\Script\"
Global $Button[25], $bX = 10, $bY = 30
Global $BNS = StringSplit("NW-SE3k|NW-SE5k|DualNW-SE3k|DualNW-SE5k|NE-SW3k|NE-SW5k|DualNE-SW3k|DualNE-SW5k|" & _
                            "N-S3k|N-S5k|DualN-S3k|DualN-S5k|SE-NW3k|SE-NW5k|DualSE-NW3k|DualSE-NW5k|" & _
                            "S-N3k|S-N5k|DualS-N3k|DualS-N5k|SW-NE3k|SW-NE5k|DualSW-NE3k|DualSW-NE5k", "|")

GUICreate("Select Script to Run")
For $i = 1 To 24
    $Button[$i] = GUICtrlCreateButton($BNS[$i], $bX, $bY, 86)
    $bX += 86
    If Not Mod($i, 4) Then
        $bX = 10
        $bY += 30
    EndIf
Next
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            For $i = 1 To 24
                If $msg = $Button[$i] Then
                    If FileExists($sPath & $BNS[$i] & ".exe") Then
                        Run($sPath & $BNS[$i] & ".exe")
                    Else
                        MsgBox(0, "Error....", "File not found:" & @LF & $sPath & $BNS[$i] & ".exe")
                    EndIf
                EndIf
            Next
    EndSwitch
Wend

Cheers

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