Jump to content

create checkboxes in sections


Fran
 Share

Recommended Posts

Hi there.

I need to create a series of checkboxes. There are quite a few of them though and they are running of the screen.

Can someone help me with a script to create them in sections of 10 or something.

So, when the tenth box is created, the next one starts at the top to the right and so on.

Here is an extract from my script:

#include <GUIConstantsEx.au3>

Local $y = 1024, $z = 768, $g = 15 ;y:gui width, g:margin, z:gui height

GUICreate("Test",$y,$z)

Dim $iMax = 29
Dim $chk[$iMax]
Global $type[$iMax] = ["HC200", "HC300", "HCA3L", "HCA4L", "HCA4P", "SB200", "SB300", "SBA3L", "SBA4L", "SBA4P", "SCA4P", "SCA5L", "SCMIN", "CALA4", "CALA3", "CTENT", "PGA1L", "PGA1P", "PGA2L", "PGA2P", "PUZA3", "PUZA4", "PFLIP", "POSTC", "ULT150", "ULT200", "ULT200E", "ULT300", "ULT300E"]
For $i = 0 To $iMax - 1
    $chk[$i] = GUICtrlCreateCheckbox("photobooks" & ($i+1), $g, 100 + ($i * 30), 80, 20)
Next
For $iIndex = 0 To $iMax - 1
    GUICtrlSetData($chk[$iIndex], $type[$iIndex])
Next

Main()

Func Main()
    GUISetState()
        While 1
        Switch GUIGetMsg()

            Case $GUI_EVENT_CLOSE
                Exit

EndSwitch
WEnd
EndFunc

And a screenshot of what I'm trying to accomplish attached.

post-58833-12843637825437_thumb.png

Link to comment
Share on other sites

  • Moderators

Fran,

Use nested loops. ;)

You have already worked out how to increase the Y value each time - just do the same for the X value - like this: ;)

#include <GUIConstantsEx.au3>

Local $y = 1024, $z = 768, $g = 15 ;y:gui width, g:margin, z:gui height

GUICreate("Test",$y,$z)

Dim $iMax = 29
Dim $chk[$iMax]
Global $type[$iMax] = ["HC200", "HC300", "HCA3L", "HCA4L", "HCA4P", "SB200", "SB300", "SBA3L", "SBA4L", "SBA4P", "SCA4P", "SCA5L", "SCMIN", "CALA4", "CALA3", "CTENT", "PGA1L", "PGA1P", "PGA2L", "PGA2P", "PUZA3", "PUZA4", "PFLIP", "POSTC", "ULT150", "ULT200", "ULT200E", "ULT300", "ULT300E"]

For $iX = 0 To 2
    For $iY = 0 To 9
        $iIndex = ($iX * 10) + $iY
        If $iIndex = $iMax Then ExitLoop
        $chk[$iIndex] = GUICtrlCreateCheckbox("photobooks" & ($iIndex + 1), ($iX * 100) + 10, ($iY * 30) + 10, 80, 20)
        GUICtrlSetData($chk[$iIndex], $type[$iIndex])
    Next
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

wakillon,

Quite clear. ;)

Normally I would use checkboxes if I wanted multiple selections. but you might like to try this trick if you insist on radio buttons: :)

#include <GUIConstantsEx.au3>

Local $y = 1024, $z = 768, $g = 15 ;y:gui width, g:margin, z:gui height

GUICreate("Test",$y,$z)

Dim $iMax = 29
Dim $chk[$iMax]
Global $type[$iMax] = ["HC200", "HC300", "HCA3L", "HCA4L", "HCA4P", "SB200", "SB300", "SBA3L", "SBA4L", "SBA4P", "SCA4P", "SCA5L", "SCMIN", "CALA4", "CALA3", "CTENT", "PGA1L", "PGA1P", "PGA2L", "PGA2P", "PUZA3", "PUZA4", "PFLIP", "POSTC", "ULT150", "ULT200", "ULT200E", "ULT300", "ULT300E"]

For $iX = 0 To 2
    For $iY = 0 To 9
        $iIndex = ($iX * 10) + $iY
        If $iIndex = $iMax Then ExitLoop
        GUIStartGroup() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $chk[$iIndex] = GUICtrlCreateRadio("photobooks" & ($iIndex + 1), ($iX * 100) + 10, ($iY * 30) + 10, 80, 20)
        GUICtrlSetData($chk[$iIndex], $type[$iIndex])
    Next
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

wakillon,

may be it's impossible ?

Not in this case: :)

#include <GUIConstantsEx.au3>

Local $y = 1024, $z = 768, $g = 15 ;y:gui width, g:margin, z:gui height

GUICreate("Test",$y,$z)

Dim $iMax = 29
Dim $chk[$iMax]
Global $type[$iMax] = ["HC200", "HC300", "HCA3L", "HCA4L", "HCA4P", "SB200", "SB300", "SBA3L", "SBA4L", "SBA4P", "SCA4P", "SCA5L", "SCMIN", "CALA4", "CALA3", "CTENT", "PGA1L", "PGA1P", "PGA2L", "PGA2P", "PUZA3", "PUZA4", "PFLIP", "POSTC", "ULT150", "ULT200", "ULT200E", "ULT300", "ULT300E"]

For $iX = 0 To 2
    GUIStartGroup() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    For $iY = 0 To 9
        $iIndex = ($iX * 10) + $iY
        If $iIndex = $iMax Then ExitLoop

        $chk[$iIndex] = GUICtrlCreateRadio("photobooks" & ($iIndex + 1), ($iX * 100) + 10, ($iY * 30) + 10, 80, 20)
        GUICtrlSetData($chk[$iIndex], $type[$iIndex])
    Next
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

You can now select one value in each column, which is what you asked for. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@M23

I've created my boxes now.

Before I had split them into sets myself, but now my code is about 100 lines shorter ;)

Global $cntALL = 29 ;amount of album types in list
$rows = 10 ;number of rows
Dim $iMax = $cntALL
$round = Round($iMax / $rows + 0.5, 0)
$box3 = GUICtrlCreateGroup("Album Types", ($y / 2) + $g, ($g * 4) + 60 + 30, ($g * 2) + 100 * $round, ($g * 2) + (30 * $rows))
Dim $chk[$iMax]
Global $type[$iMax] = ["HC200", "HC300", "HCA3L", "HCA4L", "HCA4P", "SB200", "SB300", "SBA3L", "SBA4L", "SBA4P", "SCA4P", "SCA5L", "SCMIN", "CALA4", "CALA3", "CTENT", "PGA1L", "PGA1P", "PGA2L", "PGA2P", "PUZA3", "PUZA4", "PFLIP", "POSTC", "ULT150", "ULT200", "ULT200E", "ULT300", "ULT300E"]
For $iX = 0 To $round - 1
    For $iY = 0 To $rows - 1
        $iIndex = ($iX * $rows) + $iY
        If $iIndex = $iMax Then ExitLoop
        $chk[$iIndex] = GUICtrlCreateCheckbox("albums" & ($iIndex + 1), ($y / 2) + ($g * 2) + ($iX * 100), ($iY * 30) + ($g * 6) + 60 + 30, 80, 20)
        GUICtrlSetData($chk[$iIndex], $type[$iIndex])
    Next
Next

Problem is... I get an error when I call the following within my function. And I don't understand, because I merely replaced my old piece of code with the new variables.

For $iIndex = 0 To $cntALL - 1
        If IniRead($iniFile, "ALBUM_TYPES", $type[$iIndex], "0") = "1" Then
            GUICtrlSetState($chk[$iIndex], $GUI_CHECKED) ; line 505
        Else
            GUICtrlSetState($chk[$iIndex], $GUI_UNCHECKED)
        EndIf
    Next

The error: *.au3 (505) : ==> Subscript used with non-Array variable.:

Link to comment
Share on other sites

  • Moderators

Fran,

It looks as if you have reused the $chk variable somewhere and so deleted the array. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23

Still sort of on the same thing.

#Region -> Includes
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <file.au3>
#EndRegion -> Includes

#Region -> Options
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt('MustDeclareVars', 0)
#EndRegion -> Options

#Region -> Declarations
Global $configDir = @ScriptDir & "\config\"
Global $imageDIR = @ScriptDir & "\images\"
#EndRegion

$gui = GUICreate("Link Mphoto EXE to Theme", 860, 600)
$aFileList = _FileListToArray($configDir & "\themes\", "*.ini", 1)
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$iMax = $aFileList[0]
$rows = 17
$round = Round($iMax / $rows + 0.5, 0)
Dim $theme[$iMax], $input[$iMax], $but[$iMax]
For $iX = 0 To $round - 1
    For $iY = 0 To $rows - 1
        $iIndex = ($iX * $rows) + $iY
        If $iIndex = $iMax Then ExitLoop
        $theme[$iIndex] = GUICtrlCreateLabel(StringReplace($aFileList[$iIndex+1],".ini",""), 15 + ($iX * 280), 15 + ($iY * 30), 80, 20)
        $input[$iIndex] = GUICtrlCreateInput(StringReplace($aFileList[$iIndex+1],".ini",""), 15 + ($iX * 280)+80, 15 + ($iY * 30), 100, 20)
        $but[$iIndex] = GUICtrlCreateButton("Browse...", 15 + ($iX * 280)+100+80 + 5,15 + ($iY * 30), 40, 20)
        GUICtrlSetFont(-1, 6)
    Next
Next


_Main()

Func _Main()

GUISetState()
While 1
Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
        Exit

#Region need help :)
Case $but[$iIndex]
    $var = FileOpenDialog("Choose a file","\\venus\temp\content updates\", "M-Photo exe(*.exe)")
    If @error Then
        MsgBox(4096, "Oops!","No file chosen.")
    Else
        GUICtrlSetData($input[$iIndex], $var)
    EndIf
#EndRegion

EndSwitch
WEnd

EndFunc

I'm sure from my script you can figure what I'm trying to do ;)

I know the Case $but[$iIndex] won't work, but there must be a way to get around this without having to create a million cases (since I also won't know how many of these cases to create because the number of buttons depend on the number of files in the dir).

Am I making things to complicated for myself?

Link to comment
Share on other sites

  • Moderators

Fran,

there must be a way to get around this

There certainly is! You can do it like this: ;)

#Region -> Includes
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <file.au3>
#EndRegion -> Includes

#Region -> Options
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt('MustDeclareVars', 0)
#EndRegion -> Options

#Region -> Declarations
Global $configDir = @ScriptDir & "\config\"
Global $imageDIR = @ScriptDir & "\images\"
#EndRegion -> Declarations

$gui = GUICreate("Link Mphoto EXE to Theme", 860, 600)
$aFileList = _FileListToArray($configDir & "\themes\", "*.ini", 1)
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$iMax = $aFileList[0]
$rows = 17
$round = Round($iMax / $rows + 0.5, 0)
Dim $theme[$iMax], $input[$iMax], $but[$iMax]
For $iX = 0 To $round - 1
    For $iY = 0 To $rows - 1
        $iIndex = ($iX * $rows) + $iY
        If $iIndex = $iMax Then ExitLoop
        $theme[$iIndex] = GUICtrlCreateLabel(StringReplace($aFileList[$iIndex + 1], ".ini", ""), 15 + ($iX * 280), 15 + ($iY * 30), 80, 20)
        $input[$iIndex] = GUICtrlCreateInput(StringReplace($aFileList[$iIndex + 1], ".ini", ""), 15 + ($iX * 280) + 80, 15 + ($iY * 30), 100, 20)
        $but[$iIndex] = GUICtrlCreateButton("Browse...", 15 + ($iX * 280) + 100 + 80 + 5, 15 + ($iY * 30), 40, 20)
        GUICtrlSetFont(-1, 6)
    Next
Next

GUISetState()

_Main()

Func _Main()


    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                Exit

                #Region got help :)
            Case Else
                For $i = 0 To $iMax - 1
                    If $iMsg = $but[$i] Then
                        MsgBox(0, "", "You pressed button " & $i + 1)
                        ExitLoop
                    EndIf
                Next
                #EndRegion got help :)

        EndSwitch
    WEnd

EndFunc   ;==>_Main

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Case Else
                For $i = 0 To $iMax - 1
                    If $iMsg = $but[$i] Then
                        MsgBox(0, "", "You pressed button " & $i + 1)
                        ExitLoop
                    EndIf
                Next
                #EndRegion got help :)

All clear? ;)

M23

So.... if any other button (apart from the buttons that I've actually mentioned in my cases) is pressed, then it will execute whatever I've got in the "Else" case.

Am I understanding this correctly?

Link to comment
Share on other sites

  • Moderators

Fran,

Let me explain in a bit more detail.

Here we are looking to trap one of a large number of ControlIDs, which we have handily stored in array. Your GUIGetMsg loop checks for specific controls as normal, but rather than add a whole list of Case $but[1], etc we can use a loop to run through the ControlIDs in the array and see if any match. If one does, we now know the index in the array that matches that button - of course it also gives us the index of the corresponding input! :) So you can now read the correct input and do what you wish with it in the code.

Note that for this to work, you need to actually store the return value of GUIGetMsg in a variable because you need to compare it in the loop.

Clearer? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hey M23!

I don't know if I've done this correctly....

I've added an "update" button and if any of the input boxes have been changed, I need to copy those files to a new destination.

Nothing wants to copy though. I've tried a few things, but I'm just not winning.

I've created $change[] labels so I could see if it actually updates the value to "1", but it doesn't need to be a label.

I'd appreciate your help with this one ;)

Here's my code:

$gui = GUICreate("Link Mphoto EXE to Theme", $y, $z)
$butUpdate = GUICtrlCreateButton("Update",$y - 90 - $g,$z - 30 - $g,90, 30)
$aFileList = _FileListToArray($configDir & "\themes\", "*.ini", 1)
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$iMax = $aFileList[0]
$rows = 17
$round = Round($iMax / $rows + 0.5, 0)
Dim $theme[$iMax], $input[$iMax], $but[$iMax], $change[$iMax]
For $iX = 0 To $round - 1
    For $iY = 0 To $rows - 1
        $iIndex = ($iX * $rows) + $iY
        If $iIndex = $iMax Then ExitLoop
        $theme[$iIndex] = GUICtrlCreateLabel(StringReplace($aFileList[$iIndex+1],".ini",""), 15 + ($iX * 280), 15 + ($iY * 30), 80, 20)
        $input[$iIndex] = GUICtrlCreateInput(StringReplace($aFileList[$iIndex+1],".ini",""), 15 + ($iX * 280)+80, 15 + ($iY * 30), 100, 20)
        $but[$iIndex] = GUICtrlCreateButton("Browse...", 15 + ($iX * 280)+100+80 + 5,15 + ($iY * 30), 40, 20)
        $change[$iIndex] = GUICtrlCreateLabel("0", 15 + ($iX * 280)+100+80 + 5+42,15 + ($iY * 30), 40, 20)
        GUICtrlSetFont(-1, 6)
    Next
Next


_Main()

Func _Main()

GUISetState()
While 1
$iMsg = GUIGetMsg()
Switch($iMsg)
    Case $GUI_EVENT_CLOSE
        Exit

            Case Else
                Dim $var[$iMax]
                For $i = 0 To $iMax - 1
                        If $iMsg = $but[$i] Then
                        $var[$i] = FileOpenDialog("Choose a file","\\venus\temp\content updates\", "M-Photo exe(*.exe)")
                        If @error Then
                            ExitLoop
                        Else
                            GUICtrlSetData($input[$i], $var[$i])
                            GUICtrlSetData($change[$i],"1")   ;????????????????
                        EndIf
                        ExitLoop
                    EndIf
                Next

EndSwitch

Switch($iMsg)
        Case $GUI_EVENT_CLOSE
        Exit

        Case $butUpdate
                For $i = 0 To $iMax - 1
                        GUICtrlSetState($theme[$i], $GUI_DISABLE)
                        GUICtrlSetState($input[$i], $GUI_DISABLE)
                        GUICtrlSetState($but[$i], $GUI_DISABLE)
                Next
        $popup = Run(@ScriptDir & "\GUI\popup.exe","","",$STDERR_MERGED)
        #Region need help :)
                For $i = 0 To $iMax - 1
                        If GUICtrlRead($change[$i]) = "1" Then
                            FileCopy($var[$i], @ScriptDir & "\config\mphoto_exe\"&GUICtrlRead($theme[$i])&" - Mphoto.exe",1)
                        EndIf

                Next
        #EndRegion

        _KillProcess($popup)
        ExitLoop
EndSwitch
WEnd

EndFunc
Link to comment
Share on other sites

  • Moderators

Fran,

A couple of points:

- No need to use an array to store the reset file - you can just read the input. ;)

- No need for 2 While...WEnd loops - one is quite enough. ;)

- At the moment you are exiting after the update - is that what you want to do? if not, just remove the ExitLoop command and re-enable the controls.

- Finally, PLEASE add the includes, function code and variable declarations when you post something. It is a real pain having to add or comment out several lines before the code will even run! :)

Here is how I have amended the code you posted:

$gui = GUICreate("Link Mphoto EXE to Theme", $y, $z)
$butUpdate = GUICtrlCreateButton("Update",$y - 90 - $g,$z - 30 - $g,90, 30)

$aFileList = _FileListToArray($configDir & "\themes\", "*.ini", 1)
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$iMax = $aFileList[0]
Global $theme[$iMax], $input[$iMax], $but[$iMax], $change[$iMax] ; Do not use DIM!

$rows = 17
$round = Round($iMax / $rows + 0.5, 0)

For $iX = 0 To $round - 1
    For $iY = 0 To $rows - 1
        $iIndex = ($iX * $rows) + $iY
        If $iIndex = $iMax Then ExitLoop
        $theme[$iIndex] = GUICtrlCreateLabel(StringReplace($aFileList[$iIndex + 1], ".ini", ""), 15 + ($iX * 280), 15 + ($iY * 30), 80, 20)
        $input[$iIndex] = GUICtrlCreateInput(StringReplace($aFileList[$iIndex + 1], ".ini", ""), 15 + ($iX * 280) + 80, 15 + ($iY * 30), 100, 20)
        $but[$iIndex] = GUICtrlCreateButton("Browse...", 15 + ($iX * 280) + 100 + 80 + 5, 15 + ($iY * 30), 40, 20)
        $change[$iIndex] = GUICtrlCreateLabel("0", 15 + ($iX * 280) + 100 + 80 + 5 + 42, 15 + ($iY * 30), 40, 20)
        GUICtrlSetFont(-1, 6)
    Next
Next

_Main()

Func _Main()

    GUISetState()
    While 1
        $iMsg = GUIGetMsg()
        Switch ($iMsg)
            Case $GUI_EVENT_CLOSE
                Exit

            Case $butUpdate
                For $i = 0 To $iMax - 1
                    GUICtrlSetState($theme[$i], $GUI_DISABLE)
                    GUICtrlSetState($input[$i], $GUI_DISABLE)
                    GUICtrlSetState($but[$i], $GUI_DISABLE)
                Next

                ;$popup = Run(@ScriptDir & "\GUI\popup.exe","","",$STDERR_MERGED)

                #Region got help :)
                For $i = 0 To $iMax - 1
                    If GUICtrlRead($change[$i]) = "1" Then

                        ConsoleWrite("Copying from " & GUICtrlRead($input[$i]) & @CRLF & "to " & @ScriptDir & "\config\mphoto_exe\" & GUICtrlRead($theme[$i]) & " - Mphoto.exe")
                        ;FileCopy(GUICtrlRead($input[$i]), @ScriptDir & "\config\mphoto_exe\" & GUICtrlRead($theme[$i]) & " - Mphoto.exe", 1)

                    EndIf

                Next
                #EndRegion got help :)

                ;_KillProcess($popup)
                
                ExitLoop

            Case Else
                For $i = 0 To $iMax - 1
                    If $iMsg = $but[$i] Then
                        $var = FileOpenDialog("Choose a file", "\\venus\temp\content updates\", "M-Photo exe(*.exe)")
                        If Not @error Then
                            GUICtrlSetData($input[$i], $var)
                            GUICtrlSetData($change[$i], "1")
                        EndIf
                        ExitLoop
                    EndIf
                Next

        EndSwitch
    WEnd

EndFunc   ;==>_Main

You might notice a couple of other comments in there as well. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

PLEASE add the includes, function code and variable declarations when you post something.

Sorry about that :)

And thanks for the help once again. Every day I learn a whole bunch of new things.

I'm sure I can just about finish my app with what I've learnt so far. ;)

Thank you, thank you, thank you! ;)

Link to comment
Share on other sites

  • Moderators

Fran,

My pleasure. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@M23..

Just when you thought you're rid of me for a day or two......

I'm including my script.

For some unknown reason it doesn't copy the files anymore. I have sat for an hour and a half and I can't find the problem. I was hoping that you could throw an eye on it for me.

I'd really really appreciate it.

It was still working after I added the "calendars" tab and buttons etc, but I've commented it out because I thought that was the problem.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=GUI\images\RapidStudio Assist.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

#Region -> Includes
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <file.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#EndRegion -> Includes

#Region -> Options
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt('MustDeclareVars', 0)
#EndRegion -> Options

#Region -> Declarations
Global $configDir = @ScriptDir & "\config\"
Global $imageDIR = @ScriptDir & "\images\"
Global $mphotoEXEdir = $configDir & "\mphoto_exe\"
Local $y = 980, $z = 678, $g = 15 ;y:gui width, g:margin, z:gui height
#EndRegion -> Declarations

$gui = GUICreate("Link Mphoto EXE to Theme", $y, $z)
$tab = GUICtrlCreateTab("","",$y, $z)
$tab1 = GUICtrlCreateTabItem("Photobooks")
;~ $box = GUICtrlCreateGroup("M-Photo EXE's", 15, 30, $y - 30, $z - ($g * 8))
$aFileList = _FileListToArray($configDir & "\themes\", "*.ini", 1)
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$iMax = $aFileList[0]
$rows = 16
$round = Round($iMax / $rows + 0.5, 0)
Global $theme[$iMax], $input[$iMax], $but[$iMax], $change[$iMax], $pic[$iMax], $iniFile[$iMax]
For $iX = 0 To $round - 1
    For $iY = 0 To $rows - 1
        $iIndex = ($iX * $rows) + $iY
        If $iIndex = $iMax Then ExitLoop
        $theme[$iIndex] = GUICtrlCreateLabel(StringReplace($aFileList[$iIndex + 1], ".ini", ""), 30 + ($iX * 280), 60 + ($iY * 30), 80, 20)
        $iniFile[$iIndex] = $configDir & "themes\" & $aFileList[$iIndex + 1]
        $input[$iIndex] = GUICtrlCreateInput("", 30 + ($iX * 280) + 80, 60 + ($iY * 30), 100, 20, $ES_READONLY + $ES_AUTOHSCROLL)
        $pic[$iIndex] = GUICtrlCreatePic(@ScriptDir & "\GUI\images\red.jpg", 30 + ($iX * 280) + 100 + 80 + 5 + 42, 65 + ($iY * 30), 14, 10)

        If FileExists($mphotoEXEdir & "\PHOTOBOOKS\" & StringReplace($aFileList[$iIndex + 1], ".ini", "") & " - Mphoto.exe") Then
            GUICtrlSetData($input[$iIndex], StringReplace($aFileList[$iIndex + 1], ".ini", "") & " - Mphoto.exe")
            GUICtrlSetImage($pic[$iIndex], @ScriptDir & "\GUI\images\green.jpg")
        EndIf

        $but[$iIndex] = GUICtrlCreateButton("Browse...", 30 + ($iX * 280) + 100 + 80 + 5, 60 + ($iY * 30), 40, 20)
        GUICtrlSetFont(-1, 6)
        $change[$iIndex] = 0

    Next
Next



;~ $tab2 = GUICtrlCreateTabItem("Calendars")

;~ Global $theme2[$iMax], $input2[$iMax], $but2[$iMax], $change2[$iMax], $pic2[$iMax], $iniFile2[$iMax]
;~ For $iX = 0 To $round - 1
;~  For $iY = 0 To $rows - 1
;~      $iIndex = ($iX * $rows) + $iY
;~      If $iIndex = $iMax Then ExitLoop
;~      $theme2[$iIndex] = GUICtrlCreateLabel(StringReplace($aFileList[$iIndex + 1], ".ini", ""), 30 + ($iX * 280), 60 + ($iY * 30), 80, 20)
;~      $iniFile2[$iIndex] = $configDir & "themes\" & $aFileList[$iIndex + 1]   ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;~      $input2[$iIndex] = GUICtrlCreateInput("", 30 + ($iX * 280) + 80, 60 + ($iY * 30), 100, 20, $ES_READONLY + $ES_AUTOHSCROLL)
;~      $pic2[$iIndex] = GUICtrlCreatePic(@ScriptDir & "\GUI\images\red.jpg", 30 + ($iX * 280) + 100 + 80 + 5 + 42, 65 + ($iY * 30), 14, 10)

;~      If FileExists($mphotoEXEdir & "\CALENDARS\" & StringReplace($aFileList[$iIndex + 1], ".ini", "") & "_cal - Mphoto.exe") Then
;~          GUICtrlSetData($input2[$iIndex], StringReplace($aFileList[$iIndex + 1], ".ini", "") & "_cal - Mphoto.exe")
;~          GUICtrlSetImage($pic2[$iIndex], @ScriptDir & "\GUI\images\green.jpg")
;~      EndIf

;~      $but2[$iIndex] = GUICtrlCreateButton("Browse...", 30 + ($iX * 280) + 100 + 80 + 5, 60 + ($iY * 30), 40, 20)
;~      GUICtrlSetFont(-1, 6)
;~      $change2[$iIndex] = 0

;~  Next
;~ Next

GUICtrlCreateTabItem("")

$butUpdate = GUICtrlCreateButton("Update", $y - 90 - $g, $z - 30 - ($g * 3), 90, 30)
$butCancel = GUICtrlCreateButton("Cancel", $y - (90 * 2) - ($g * 2), $z - 30 - ($g * 3), 90, 30)


_Main()

Func _Main()

    GUISetState()
    While 1
        $iMsg = GUIGetMsg()
        Switch ($iMsg)
            Case $GUI_EVENT_CLOSE, $butCancel
                $close = 1
                For $i = 0 To $iMax - 1
                    If $change[$i] = 1 Then
                        $close = 0
                    EndIf
                Next
                If $close = 0 Then
                    If MsgBox(8196, "Cancel", "All themes have not been updated." & @CRLF & "Are you sure you want to exit?") = 6 Then Exit
                Else
                    Exit
                EndIf

            Case $butUpdate
                For $i = 0 To $iMax - 1
                    ;Photobooks tab disable
                    GUICtrlSetState($theme[$i], $GUI_DISABLE)
                    GUICtrlSetState($input[$i], $GUI_DISABLE)
                    GUICtrlSetState($but[$i], $GUI_DISABLE)
                Next

                $popup = Run(@ScriptDir & "\GUI\popup.exe")
                Sleep(2000)

                For $i = 0 To $iMax - 1
                    ;Photobooks copy files
                    If $change[$i] = 1 Then
                        FileCopy(GUICtrlRead($input[$i]), @ScriptDir & "\config\mphoto_exe\PHOTOBOOKS\" & GUICtrlRead($theme[$i]) & " - Mphoto.exe", 1)
                    EndIf
                Next

;~              For $i = 0 To $iMax - 1
;~                  ;Calendars tab disable
;~                  GUICtrlSetState($theme2[$i], $GUI_DISABLE)
;~                  GUICtrlSetState($input2[$i], $GUI_DISABLE)
;~                  GUICtrlSetState($but2[$i], $GUI_DISABLE)
;~              Next
;~              For $i = 0 To $iMax - 1
;~                  ;Calendars copy files
;~                  If $change2[$i] = 1 Then
;~                      FileCopy(GUICtrlRead($input2[$i]), @ScriptDir & "\config\mphoto_exe\CALENDARS\" & GUICtrlRead($theme2[$i]) & "_cal - Mphoto.exe", 1)
;~                  EndIf
;~              Next





                _KillProcess($popup)
;~              ExitLoop
                #Region Re-enable Form
                ;Photobooks reset form and write to ini file
                For $i = 0 To $iMax - 1
                    GUICtrlSetState($theme[$i], $GUI_ENABLE)
                    GUICtrlSetState($input[$i], $GUI_ENABLE)
                    GUICtrlSetState($but[$i], $GUI_ENABLE)
                    GUICtrlSetImage($pic[$i], @ScriptDir & "\GUI\images\red.jpg")
                    $MPHOTO_EXE = StringReplace($aFileList[$i + 1], ".ini", "") & " - Mphoto.exe"
                    If FileExists($mphotoEXEdir & "PHOTOBOOKS\" & $MPHOTO_EXE) Then
                        GUICtrlSetData($input[$i], $MPHOTO_EXE)
                        IniWrite($iniFile[$i],"PHOTOBOOKS","MPHOTO_EXE",$MPHOTO_EXE)
                        GUICtrlSetImage($pic[$i], @ScriptDir & "\GUI\images\green.jpg")
                    EndIf
                    $change[$i] = 0
                Next
                ;Calendars reset form and write to ini file
;~              For $i = 0 To $iMax - 1
;~                  GUICtrlSetState($theme2[$i], $GUI_ENABLE)
;~                  GUICtrlSetState($input2[$i], $GUI_ENABLE)
;~                  GUICtrlSetState($but2[$i], $GUI_ENABLE)
;~                  GUICtrlSetImage($pic2[$i], @ScriptDir & "\GUI\images\red.jpg")
;~                  $MPHOTO_EXE = StringReplace($aFileList[$i + 1], ".ini", "") & " - Mphoto.exe"
;~                  If FileExists($mphotoEXEdir & "CALENDARS\" & $MPHOTO_EXE) Then
;~                      GUICtrlSetData($input2[$i], $MPHOTO_EXE)
;~                      IniWrite($iniFile[$i],"CALENDARS","MPHOTO_EXE",$MPHOTO_EXE)
;~                      GUICtrlSetImage($pic2[$i], @ScriptDir & "\GUI\images\green.jpg")
;~                  EndIf
;~                  $change2[$i] = 0
;~              Next
                #EndRegion

            Case Else
                For $i = 0 To $iMax - 1
                    ;Photobooks choose files
                    If $iMsg = $but[$i] Then
                        $var = FileOpenDialog("Choose a file", "\\venus\temp\content updates\", "M-Photo exe(*.exe)")
                        If @error Then
                            ExitLoop
                        Else
                            GUICtrlSetData($input[$i], $var)
                            GUICtrlSetImage($pic[$i], @ScriptDir & "\GUI\images\orange.jpg")
                            $change[$i] = 1
                        EndIf
                        ExitLoop
                    EndIf
;~                  ;Calendars choose files
;~                  If $iMsg = $but2[$i] Then
;~                      $var2 = FileOpenDialog("Choose a file", "\\venus\temp\content updates\", "M-Photo exe(*.exe)")
;~                      If @error Then
;~                          ExitLoop
;~                      Else
;~                          GUICtrlSetData($input2[$i], $var2)
;~                          GUICtrlSetImage($pic2[$i], @ScriptDir & "\GUI\images\orange.jpg")
;~                          $change2[$i] = 1
;~                      EndIf
;~                      ExitLoop
;~                  EndIf
                Next

        EndSwitch
    WEnd
EndFunc   ;==>_Main

Func _KillProcess($Process)
    If ProcessExists($Process) Then
        ProcessClose($Process)
        ProcessWaitClose($Process)
    EndIf
EndFunc   ;==>_KillProcess
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...