Jump to content

Dynamic Checkbox Problems


AcidCorps
 Share

Recommended Posts

#include 
#include 

$Dir = @ScriptDir & '\Packs\'
$Packs = _FileListToArray($Dir)
Dim $Checks[$Packs[0]]


GUICreate('Packs', 300, 300)
For $i = 1 To $Packs[0] - 1
    $Height = $i * 20
    $Checks[$i] = GUICtrlCreateCheckbox($Packs[$i], 5, $Height, 150, 15)
Next


GUISetState()
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            If GUICtrlRead($Checks[1]) = 1 Then MsgBox(0,'','Hello World')
        Exit
    EndSelect
WEnd

When I run the above script it shows me one less file then is put into the 'Packs' directory, however I tried For $i = 1 To $Packs[0] and $i = 0 To $Packs[0] and in bothe cases got an incorrect subscript amount error

how can I have it show me all the files in the 'packs' directory

Link to comment
Share on other sites

Hi,

Try

Dim $Checks[$Packs[0] + 1]oÝ÷ Ø  ݺǺÚ"µÍÜ   ÌÍÚHHHÈ ÌÍÔXÚÜÖÌoÝ÷ Ù.j[((!·§¶Ú.±æ[^­©Ý~V ¢{axX¥zX¬µ:®¶²~éܶ*'z®¶­sbb33cµ6·2ÒôfÆTÆ7EFô'&b33c´F"ÂgV÷C²¢æWRgV÷C²ÂoÝ÷ Ù*"·l²¶§X¤zØb±«­¢+Ø¥¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì(¥¹±Õ±Ðí¥±¹ÔÌÐì((ÀÌØí¥ÈôMÉ¥ÁѥȵÀìÌäìÀäÈíA­ÌÀäÈìÌäì(ÀÌØíA­Ìô}¥±1¥ÍÑQ½ÉÉä ÀÌØí¥È°ÅÕ½Ð쨸¨ÅÕ½Ðì°Ä¤ì=¹±ä±¥ÍÑ¥¹¥±Ì¹½Ð½±ÉÌ)¥´ÀÌØí
¡­ÍlÀÌØíA­ÍlÁt¬Åt()U%
ÉÑ ÅÕ½Ðí9ÕµÈ=A­Ì½Õ¹èÅÕ½ÐìµÀìÀÌØíA­ÍlÁt°ÌÀÀ° ÀÌØíA­ÍlÁt¬Ä¤¨ÈÀ¤)½ÈÀÌØí¤ôÄQ¼ÀÌØíA­ÍlÁt(ÀÌØí
¡­ÍlÀÌØí¥tôU%
Ñɱ
ÉÑ
¡­½à ÀÌØíA­ÍlÀÌØí¥t°Ô°ÀÌØí¤¨ÈÀ°ÄÔÀ°ÄÔ¤)9áÐ)U%MÑMÑÑ ¤()]¡¥±Ä(ÀÌØí5ÍôU%Ñ5Í ¤(M±Ð(
ÍÀÌØí5ÍôÀÌØíU%}Y9Q}
1=M(%U%
ÑɱI ÀÌØí
¡­ÍlÅt¤ôÄQ¡¸5Í    ½à À°ÌäìÌäì°Ìäí!±±¼]½É±Ìäì¤(á¥Ð(%¹M±Ð$)]¹

Cheers

Edited by smashly
Link to comment
Share on other sites

Another look...

#include <GUIConstants.au3>
#include <file.au3>

$Dir = @ScriptDir & '\Packs\'
$Packs = _FileListToArray($Dir)
Dim $Checks[$Packs[0] + 1]

$Height = ($Packs[0] * 20) + 50

If $Height > @DesktopHeight Then 
    MsgBox(0x0,"Error", "There are more files than can be displayed    ", 3)
    $Height = @DesktopHeight - 50
EndIf

GUICreate("Number Of Packs Found: " & $Packs[0], 300, $Height)
For $i = 1 To $Packs[0] 
    $Height = $i * 20
    $Checks[$i] = GUICtrlCreateCheckbox($Packs[$i], 5, $Height, 150, 15)
Next

$btn = GUICtrlCreateButton("Start", 200, 150, 60, 30)

GUISetState()
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
        Case $Msg = $btn
            
            for $x = 1 to $Packs[0]
            If _IsChecked($Checks[$x]) Then 
                ; do something Run or ??
                MsgBox(0x0,"#=" &$x,"control = " & GUICtrlRead($Checks[$x] & "   ", 1), 2)
            EndIf
            Next
    EndSelect
WEnd

Func _IsChecked($control)
    Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

  • 3 years later...

I'm having a similar problem. When I use "Run or RunWait" the script performs the "CheckBox" selected by the amount selected. Type two "CheckBox" selected with two different programs, both programs will be run twice each. Still could not solve.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>

AutoItSetOption ("TrayIconDebug", 1)
$folderToList = @ScriptDir
$vSpacer = 90
$hSpacer = 16
$tasks = ''
$noFilesFound = ''
Global $chkList[100], $XS_n, $iCount

$appList = _FileListToArray($folderToList, "*", 2)
If @error = 1 Then
    Exit
EndIf

Global $chkList[Ubound($chkList)] ; Declare an array to hold the checkbox ControlIDs

If $appList = '' Then
    $noFilesFound = 'Nenhum arquivo ou pasta encontrado.'
EndIf

;~ _ArrayDisplay($appList)
$autoAppLister = GUICreate("Instaladores",593, 412, 192, 124)
$Fundo = GUICtrlCreatePic("install_bg.bmp", 0, 0, 592, 412, $WS_GROUP)
$appListGrp = GUICtrlCreateGroup("Lista de jogos", 8, 64, 353, 295)
If $noFilesFound <> '' Then
    $noFilesLbl = GUICtrlCreateLabel($noFilesFound, 16, 152, 318, 28, $SS_CENTER)
    GUICtrlSetFont(-1, 8, 400, 0, "MS Sans Serif")
Else
    If $appList <> '' Then
        For $i = 1 To $appList[0]
            XPStyleToggle(1)
            $chkList[$i] = GUICtrlCreateCheckbox($appList[$i], $hSpacer, $vSpacer, 161, 17) ; Save the ControlIds on the new array 
            GUICtrlSetFont(-1, 11, 800, 0, "Segoe UI")
            GUICtrlSetColor(-1, 0xFFFFFF)
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            XPStyleToggle(0);turn XP themes on again
            $vSpacer += 16
            If $vSpacer > 330 Then
                $vSpacer = 90
                $hSpacer = 192
            EndIf
        Next
    EndIf
EndIf

GUICtrlCreateGroup("", -99, -99, 1, 1)

$installBtn = GUICtrlCreateButton("Checked Boxes", 488, 200, 75, 25, $WS_GROUP)
GUICtrlSetState($installBtn,$GUI_DISABLE)
$ButtonCheck = GUICtrlCreateButton("Tudo", 488, 160, 75, 25)
$hProgress = GUICtrlCreateProgress(168, 376, 406, 17)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $installBtn
            GUICtrlSetData($hProgress, 0)
            If $iCount > 0 Then
                ; How much is each checkbox worth?
                $iSegment = Int(100 / $iCount)
                ; Now increase the progress by that amount each time
                $iCountPom = $iCount ; [reserve global $iCount
                Do
                    GUICtrlSetData($hProgress, GUICtrlRead($hProgress) + $iSegment)
;~                      $iCountPom -= 1
                    for $i = 1 to $appList[0]
                    If RunWait($appList[$i] &"\" &$appList[$i] &".exe") = 1 Then
                        $iCountPom -= 1
                        EndIf
                    Next
                Until $iCountPom < 0
                ; Wait 10 secs
                Sleep(1000)
            EndIf
            _listCheck()
;~          for $i = 1 to $appList[0]
;~          If IsChecked($chkList[$i]) Then RunWait($appList[$i] &"\" &$appList[$i] &".exe")
;~              next 

        Case $ButtonCheck
            Switch GUICtrlRead($ButtonCheck)
                Case "Tudo"     ;Check All
                    For $i = 1 To $appList[0]
                        GUICtrlSetState ( $chkList[$i] , $GUI_CHECKED )
                    Next
                    $iCount = $appList[0]
                    GUICtrlSetData($ButtonCheck, "Nada")
                Case "Nada"     ;Clear All
                    For $i = 1 To $appList[0]
                        GUICtrlSetState ( $chkList[$i] , $GUI_UNCHECKED )
                    Next
                    $iCount = 0
                    GUICtrlSetData($ButtonCheck, "Tudo")
            EndSwitch
        Case Else
            ; call CanEnableInstallBtn() only when one of checkbox changes
            For $i = 1 To $appList[0]
                If $nMsg = $chkList[$i] Then CanEnableInstallBtn()
            Next
    EndSwitch
WEnd

Func CanEnableInstallBtn()
    $iCount = 0
    For $i = 1 To $appList[0]
        If GUICtrlRead($chkList[$i]) = 1 Then $iCount += 1
    Next
    If $iCount > 0 And BitAND(GUICtrlGetState($installBtn),$GUI_DISABLE) Then GUICtrlSetState($installBtn,$GUI_ENABLE)
    If $iCount = 0 And BitAND(GUICtrlGetState($installBtn),$GUI_ENABLE) Then GUICtrlSetState($installBtn,$GUI_DISABLE)
EndFunc

Func _listCheck()
    For $i = 1 To $appList[0]
        If GUICtrlRead($chkList[$i]) = 1 Then ; Check the checkboxes
            $tasks &= $appList[$i] & @LF ; Add the text from the file list
        EndIf
    Next
    $okPressed = MsgBox(0, '', $tasks)
    If $okPressed = 1 Then
        $tasks = ''
    EndIf
EndFunc   ;==>_listCheck

Func XPStyleToggle($Off = 1)
     If Not StringInStr(@OSTYPE, "WIN32_NT") Then Return 0
      
     If $Off Then
        $XS_n = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
         DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
         Return 1
     ElseIf IsArray($XS_n) Then
         DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $XS_n[0])
         $XS_n = ""
         Return 1
     EndIf
     Return 0
 EndFunc
 
;~   for $i = 1 to $apps[0]
;~    If IsChecked($APP_CHKBOX[$i]) Then RunWait($apps[$i])
;~   next
;~ ...
  
Func IsChecked($control)
    Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = 1
EndFunc
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...