Jump to content

Incremental Variable names


Recommended Posts

I need to create variables with incremental names and then use them in a switch. I figure using an array would be easiest but I didn't really know how to tell it how big to be. What I did seems sloppy and I don't know if it will work. And then I have no idea how to make a case statement based on that.

CODE
#include <File.au3>

#include <Array.au3>

#include <GUIConstants.au3>

$array = _FileListToArray (@ScriptDir, "*", 2)

_ArrayDisplay ($array, "start")

$i = $array[0]

Dim $combo[$i]

$x = 0

$left = 24

$top = 24

$width = 97

$height = 17

$Form1 = GUICreate("Form1", 633, 447, 193, 125)

For $x = 1 To UBound($array) - 1

$combo[$x] = GUICtrlCreateCheckbox($array[$x] , $left, $top, $width, $height)

GUISetState(@SW_SHOW)

Next

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $combo[$x]

;something something

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

Could you provide some more info on what you are trying to do.

There are some rules when declaring vars which may not let you use a $var in the name of the var.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

GUICreate('Title', 400, 500)
Dim $TwelveCheckBoxes[12]

For $i = 1 To 3
    For $j = 1 To 4
        $TwelveCheckBoxes[$j-1+($i-1)*4] = GUICtrlCreateCheckbox($j+($i-1)*4, 30*$j+20, 30*$i+20, 30, 30)
    Next
Next

GUISetState()

Do
    Sleep(20)
Until GUIGetMsg() = -3

Silly example and bad math so it's just to show according to the raw and elements you want or have you need to use sort of pixel offsets.

Link to comment
Share on other sites

This should give you some idea of what you can do. I stored the Actions in the $Combo array as well (1 for check, 1 for uncheck). Lemme know if this is how you were thinking

#include <Array.au3>
#include <File.au3>
#include <GUIConstants.au3>
Global $Array = _FileListToArray(@ScriptDir, "*", 2), $Combo[UBound($Array)][4]

$Combo[0][0] = UBound($Combo) - 1
For $i = 1 To $Combo[0][0]
    $Combo[$i][0] = String("$Checkbox" & $i)    ;Friendly Name, no other purpose
    $Combo[$i][2] = 'MsgBox(0,"Directory: " & $Array[' & $i & '], $Combo[' & $i & '][0] & " Has just been checked")'    ;Stores Checked Command
    $Combo[$i][3] = 'MsgBox(0, "Directory: " & $Array[' & $i & '], $Combo[' & $i & '][0] & " Has just been Unchecked")' ;Stores UnChecked Command
Next
_ArrayDisplay($Array, "start")
_ArrayDisplay($Combo, "$Combo")

$Left = 24
$Top = 24
$Width = 97
$Height = 17

$Form1 = GUICreate("Form1", 633, 447, 193, 125)
For $x = 1 To $Array[0]
    $Combo[$x][1] = GUICtrlCreateCheckbox($Array[$x], $Left, $Top + (($x - 1) * 25), $Width, $Height)   ;spaces Checkboxes 25 pixels apart, starting at 24 ($Top + 0 ~ do the math)
    GUISetState(@SW_SHOW)
Next

While 1
    $nMsg = GUIGetMsg()
    For $x = 1 To $Combo[0][0]
        Switch $nMsg
            Case $Combo[$x][1]
                _Test($x)
            Case $GUI_EVENT_CLOSE
                Exit MsgBox(0, "", "Goodbye")
        EndSwitch
    Next
WEnd

Func _Test($Number)
    If Not FileExists($Array[$Number]) Then Return
    If ControlCommand($Form1, "", $Combo[$Number][1], "Ischecked", "") Then
        Execute($Combo[$Number][2])
    Else
        Execute($Combo[$Number][3])
    EndIf
EndFunc   ;==>_Test

I'm just not sure how you can resize the Gui if you have a lot of directories..I only had 8, so it displayed fine

Link to comment
Share on other sites

@bo8ster- I'm going to zip all the folders in a directory (the script for that is done) but then I thought it would be nice to build an interface with check boxes if you wanted to delete the original folders after the zip is created. On my wife's computer she has a bunch of folders but not enough space for me to create all the zip files and go back to delete the originals afterwards so I'd have to create/delete. And after I started building it the idea of checkboxes on the fly seemed like it might be pretty useful in the future.

@Authenticity- I have offsets in my original code but I didn't paste it in the example I posted.

@Varian- On initial run this is looking pretty sweet. I think it's doing what I want. Need to play with it a bit when I have some time to make sure.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
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...