Sign in to follow this  
Followers 0
aharker

Cannot Enable Checkboxes

3 posts in this topic

I inherited this script and have been able to figure out a few bugs and things that need changed, but I'm having an issue enabling the checkboxes. Half the checkboxes were checked and disabled so that the end-user couldn't uncheck them. I commented out the lines that I thought were the issue, and same result. I changed the GUICtrlSetState from GUI_DISABLE to GUI_ENABLE and I still had the same result. Any help would be greatly appreciated!

Here is the full script:

;#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=logo.ico
#AutoIt3Wrapper_Outfile=PC Records Review.exe
#AutoIt3Wrapper_Res_LegalCopyright=Property of CareSource.
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>
#include <GuiListView.au3>

Global $iTimeHorizon = 1

#region ### DISCLAIMER

MsgBox(64, "PC Record Review Utility", "" & @CRLF & "This program allows you to delete files older than " & $iTimeHorizon & " years." & _
        @CRLF & "All deleted local files are sent to Recycle Bin. All deleted network files will require an IT ticket to be recoverable." & @CRLF & "Please use this program responsibly.")

#endregion ### DISCLAIMER

#region ### STARTUP Ops

FileDelete(@ScriptDir & "\FileList.txt")

#endregion ### STARTUP Ops

#region ### START Koda GUI section ### Form=

$iLeftMargin = 10
$iItemHeight = 20
$iItemWidth = 90

$Form1 = GUICreate("PC Records Review Utility 1.0", 915, 568, 122, 124, $WS_SIZEBOX)

$btnDirectory = GUICtrlCreateButton("Search Directory", $iLeftMargin, 30, $iItemWidth, $iItemHeight)
$inpPath = GUICtrlCreateInput("", $iLeftMargin + $iItemWidth + $iLeftMargin, 30, 2 * $iItemWidth, $iItemHeight)


$Label2 = GUICtrlCreateLabel("File Types included in search:", $iLeftMargin, 60, 144, 17)

$ckbDoc = GUICtrlCreateCheckbox("doc / docx", $iLeftMargin, 90, $iItemWidth, $iItemHeight)
$ckbXls = GUICtrlCreateCheckbox("xls / xlsx", $iLeftMargin, 120, $iItemWidth, $iItemHeight)
$ckbPpt = GUICtrlCreateCheckbox("ppt / pptx", $iLeftMargin, 150, $iItemWidth, $iItemHeight)
$ckbTxt = GUICtrlCreateCheckbox("txt", $iLeftMargin, 180, $iItemWidth, $iItemHeight)
$ckbPdf = GUICtrlCreateCheckbox("pdf", $iLeftMargin, 210, $iItemWidth, $iItemHeight)
$ckbZip = GUICtrlCreateCheckbox("zip", $iLeftMargin, 240, $iItemWidth, $iItemHeight)
$ckbJpeg = GUICtrlCreateCheckbox("jpeg", 100, 90, $iItemWidth, $iItemHeight)
$ckbPng = GUICtrlCreateCheckbox("png", 100, 120, $iItemWidth, $iItemHeight)
$ckbHtml = GUICtrlCreateCheckbox("html", 100, 150, $iItemWidth, $iItemHeight)
$ckbMhtl = GUICtrlCreateCheckbox("mhtl", 100, 180, $iItemWidth, $iItemHeight)
$ckbAll = GUICtrlCreateCheckbox("Search all types", 100, 210, $iItemWidth, $iItemHeight)

GUICtrlSetState($ckbDoc, $GUI_CHECKED)
GUICtrlSetState($ckbXls, $GUI_CHECKED)
GUICtrlSetState($ckbPpt, $GUI_CHECKED)
GUICtrlSetState($ckbTxt, $GUI_CHECKED)
GUICtrlSetState($ckbPdf, $GUI_CHECKED)
GUICtrlSetState($ckbZip, $GUI_CHECKED)

GUICtrlSetState($ckbDoc, $GUI_ENABLE)
GUICtrlSetState($ckbXls, $GUI_ENABLE)
GUICtrlSetState($ckbPpt, $GUI_ENABLE)
GUICtrlSetState($ckbTxt, $GUI_ENABLE)
GUICtrlSetState($ckbPdf, $GUI_ENABLE)
GUICtrlSetState($ckbZip, $GUI_ENABLE)


$btnSearch = GUICtrlCreateButton("Search", $iLeftMargin, 290, 129, 41)

$lblFoundCount = GUICtrlCreateLabel("", $iLeftMargin, 343, 160, $iItemHeight)
$btnCheckAll = GUICtrlCreateButton("", $iLeftMargin, 360, 129, 41)
$btnDelete = GUICtrlCreateButton("Delete", 160, 360, 129, 41)

GUICtrlSetState($btnSearch, $GUI_DISABLE)
GUICtrlSetState($btnCheckAll, $GUI_DISABLE)
GUICtrlSetState($btnDelete, $GUI_DISABLE)

;~ $Pic1 = GUICtrlCreatePic("C:\Users\koc.m\My Documents\_ORG\ReInvent\Reinvent white.jpg", 0, 330, 360, 105, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))

Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)

;~ $hListView = GUICtrlCreateListView("Name|Directory|Date Modified|Type|Size in KB", 300, 0, 600, 530, -1, $iExWindowStyle)
$hListView = GUICtrlCreateListView("", 300, 0, 600, 530, -1, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_AddColumn($hListView, "Name", 170)
_GUICtrlListView_AddColumn($hListView, "Directory", 190)
_GUICtrlListView_AddColumn($hListView, "Date Modified", 110)
_GUICtrlListView_AddColumn($hListView, "Type", 50)
_GUICtrlListView_AddColumn($hListView, "Size in KB", 70)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)


$sSplashPath = "wait.jpg"

GUISetState(@SW_SHOW)
_GUICtrlListView_RegisterSortCallBack($hListView)

#endregion ### END Koda GUI section ###

;control used do do check/uncheck all
$iCheck = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlListView_UnRegisterSortCallBack($hListView)
            Exit
        Case $btnDirectory
            GUICtrlSetState($btnSearch, $GUI_DISABLE)
            ;get new directory
;~          $sInputDir = FileSelectFolder("Select directory", @HomePath) ;
            $sInputDir = FileSelectFolder("Select directory", "", 0, @MyDocumentsDir) ;
            GUICtrlSetData($inpPath, $sInputDir)
            GUICtrlSetState($btnSearch, $GUI_ENABLE)
        Case $btnSearch
            _search()


        Case $hListView
            _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
        Case $ckbAll

            GUICtrlSetState($ckbJpeg, $GUI_CHECKED)
            GUICtrlSetState($ckbPng, $GUI_CHECKED)
            GUICtrlSetState($ckbHtml, $GUI_CHECKED)
            GUICtrlSetState($ckbMhtl, $GUI_CHECKED)

;~
        Case $btnCheckAll
            $iCheck = $iCheck + 1
            $bCheckAll = 0
            If Mod($iCheck, 2) = 0 Then

                $bCheckAll = True
                GUICtrlSetData($btnCheckAll, "Uncheck All")
            Else
                $bCheckAll = False
                GUICtrlSetData($btnCheckAll, "Check All")
            EndIf
            _GUICtrlListView_SetItemChecked($hListView, -1, $bCheckAll)

        Case $btnDelete
            _delete()

    EndSwitch
WEnd

#region ### CLOSE Ops

_GUICtrlListView_UnRegisterSortCallBack($hListView)
FileDelete(@ScriptDir & "\FileList.txt")

#endregion ### CLOSE Ops


#region ### Functions

Func _delete()

    $aItemsForDeletion = _GUICtrlListView_CreateArray($hListView, Default)
    Local $aDeleteList[1]

    For $i = 1 To UBound($aItemsForDeletion)
        If _GUICtrlListView_GetItemChecked($hListView, $i - 1) Then
            $sDeleteItem = $aItemsForDeletion[$i][1] & $aItemsForDeletion[$i][0] & $aItemsForDeletion[$i][3]
            _ArrayAdd($aDeleteList, $sDeleteItem)
        EndIf
    Next

    If UBound($aDeleteList) = 1 Then
        MsgBox(64, "Info", "You have not selected any files for deletion.")
    Else
        $megaBytes = 0
        _ArrayDelete($aDeleteList, 0)
;~      _ArrayDisplay($aDeleteList)
         GUICtrlSetState($btnDelete, $GUI_DISABLE)
         SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        For $i = 0 To UBound($aDeleteList) - 1
            $megaBytes = $megaBytes + FileGetSize($aDeleteList[$i])
            FileRecycle($aDeleteList[$i])
        Next
         SplashOff()
        MsgBox(64, "Info", "You have deleted " & $i & " files which used " & Round($megaBytes/1048576,2) & " MB of space. Please remember to clean up your recycle bin.")
         GUICtrlSetState($btnDelete, $GUI_ENABLE)

        _search(1)

    EndIf


EndFunc   ;==>_delete

Func _search($mode = 0)
    ;clear previous search results
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))
    ;reset /uncheck
    $iCheck = 0

    $aExtensions = getExtensions()
    $sInputDir = GUICtrlRead($inpPath)
    If $sInputDir <> "" Then
        SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        ScanFolder($sInputDir, $aExtensions) ;returns txt file with all files found
        displayFiles($mode)
        FileDelete(@ScriptDir & "\FileList.txt")
        GUICtrlSetState($btnCheckAll, $GUI_ENABLE)
        GUICtrlSetState($btnDelete, $GUI_ENABLE)
        GUICtrlSetData($btnCheckAll, "Uncheck All")
        SplashOff()
    Else
        MsgBox(64, "Warning", "Search path is not defined. Please select search directory.")
    EndIf

EndFunc   ;==>_search

Func getExtensions()
    Dim $aExtensions[14]
    If GUICtrlRead($ckbDoc) = $GUI_CHECKED Then $aExtensions[0] = ".doc"
    If GUICtrlRead($ckbDoc) = $GUI_CHECKED Then $aExtensions[1] = ".docx"
    If GUICtrlRead($ckbXls) = $GUI_CHECKED Then $aExtensions[2] = ".xls"
    If GUICtrlRead($ckbXls) = $GUI_CHECKED Then $aExtensions[3] = ".xlsx"
    If GUICtrlRead($ckbPpt) = $GUI_CHECKED Then $aExtensions[4] = ".ppt"
    If GUICtrlRead($ckbPpt) = $GUI_CHECKED Then $aExtensions[5] = ".pptx"
    If GUICtrlRead($ckbTxt) = $GUI_CHECKED Then $aExtensions[6] = ".txt"
    If GUICtrlRead($ckbPdf) = $GUI_CHECKED Then $aExtensions[7] = ".pdf"
    If GUICtrlRead($ckbZip) = $GUI_CHECKED Then $aExtensions[8] = ".zip"
    If GUICtrlRead($ckbJpeg) = $GUI_CHECKED Then $aExtensions[9] = ".jpeg"
    If GUICtrlRead($ckbJpeg) = $GUI_CHECKED Then $aExtensions[10] = ".jpg"
    If GUICtrlRead($ckbPng) = $GUI_CHECKED Then $aExtensions[11] = ".png"
    If GUICtrlRead($ckbHtml) = $GUI_CHECKED Then $aExtensions[12] = ".html"
    If GUICtrlRead($ckbMhtl) = $GUI_CHECKED Then $aExtensions[13] = ".mhtl"
    If GUICtrlRead($ckbAll) = $GUI_CHECKED Then $aExtensions[14] = ".*"
    Return $aExtensions
EndFunc   ;==>getExtensions

Func displayFiles($mode = 0)

    ;step 1 read the FileList.txt and put it into an array
    Local $aFileList
    _FileReadToArray(@ScriptDir & "\FileList.txt", $aFileList)
    If @error Then
        SplashOff()
        If $mode = 0 Then MsgBox(64, "info", "No files older than " & $iTimeHorizon & " years were found in the search directory")
    Else

        Dim $aFileList2[UBound($aFileList)][5]
        Local $szDrive, $szDir, $szFName, $szExt

        For $i = 1 To UBound($aFileList) - 1
            $sFileAttributes = _PathSplit($aFileList[$i], $szDrive, $szDir, $szFName, $szExt)
            $aDateModified = FileGetTime($aFileList[$i], 0, 0)
            $sSize = Round(FileGetSize($aFileList[$i]) / 1024, 2)
            $aFileList2[$i][0] = $sFileAttributes[3] ;name
            $aFileList2[$i][1] = $sFileAttributes[1] & $sFileAttributes[2] ;directory
            $aFileList2[$i][2] = $aDateModified[0] & "/" & $aDateModified[1] & "/" & $aDateModified[2] & " " & $aDateModified[3] & ":" & $aDateModified[4] & ":" & $aDateModified[5]
            $aFileList2[$i][3] = $sFileAttributes[4] ;extension
            $aFileList2[$i][4] = $sSize ;filesize in kb

        Next

        _ArraySort($aFileList2, 0, 0, 0, 2)

        GUICtrlSetData($lblFoundCount, $aFileList[0] & " files older than " & $iTimeHorizon & " years found.")
        _ArrayDelete($aFileList2, 0)

;~  _GUICtrlListView_AddArray($hListView, $aFileList2)



        For $i = 0 To UBound($aFileList2) - 1
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aFileList2 = ' & $aFileList2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
            _GUICtrlListView_AddItem($hListView, $aFileList2[$i][0], -1, _GUICtrlListView_GetItemCount($hListView) + 1000)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][1], 1, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][2], 2, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][3], 3, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][4], 4, -1)
            _GUICtrlListView_SetItemChecked($hListView, $i, True)
        Next

    EndIf


EndFunc   ;==>displayFiles

Func ScanFolder($SourceFolder, $aExtensions)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath


    $Search = FileFindFirstFile($SourceFolder & "\*.*")

    While 1
        If $Search = -1 Then
            ExitLoop
        EndIf

        $File = FileFindNextFile($Search)
        If @error Then ExitLoop

        $FullFilePath = $SourceFolder & "\" & $File
        $FileAttributes = FileGetAttrib($FullFilePath)

        If StringInStr($FileAttributes, "D") Then
            ScanFolder($FullFilePath, $aExtensions)
        Else
            $sExt = _FileGetExt($FullFilePath)
            $aDateModified = FileGetTime($FullFilePath, 0, 0)
            $sDateModified = $aDateModified[0] & "/" & $aDateModified[1] & "/" & $aDateModified[2] & " " & $aDateModified[3] & ":" & $aDateModified[4] & ":" & $aDateModified[5]
            $iYears = _DateDiff("Y", $sDateModified, _NowCalc())
            If ((_ArraySearch($aExtensions, $sExt) <> -1 Or $aExtensions[13] <> "") And $iYears >= $iTimeHorizon) Then LogFile($FullFilePath)
        EndIf

    WEnd

    FileClose($Search)

EndFunc   ;==>ScanFolder

Func LogFile($FileName)
    $fLogFile = FileOpen(@ScriptDir & "\FileList.txt", 1)
;~  FileWriteLine(@ScriptDir & "\FileList.txt",$FileName)
    FileWriteLine($fLogFile, $FileName)
    FileClose($fLogFile)

EndFunc   ;==>LogFile

Func _FileGetExt($sPath)
    Local $NULL, $sExt
    _PathSplit($sPath, $NULL, $NULL, $NULL, $sExt)
    Return $sExt
EndFunc   ;==>_FileGetExt

#endregion ### Functions


Func _GUICtrlListView_CreateArray($hListView, $sDelimeter = '|')
    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListView)
    If $iColumnCount < 3 Then
        $iDim = 3 - $iColumnCount
    EndIf
    If $sDelimeter = Default Then
        $sDelimeter = '|'
    EndIf

    Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']]
    For $i = 0 To $iColumnCount - 1
        $aColumns = _GUICtrlListView_GetColumn($hListView, $i)
        $aReturn[0][2] &= $aColumns[5] & $sDelimeter
    Next
    $aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter))

    For $i = 0 To $iItemCount - 1
        For $j = 0 To $iColumnCount - 1
            $aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListView, $i, $j)
        Next
    Next
    Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn)
EndFunc   ;==>_GUICtrlListView_CreateArray

Here is the section that I believe to be causing me issues:

$Label2 = GUICtrlCreateLabel("File Types included in search:", $iLeftMargin, 60, 144, 17)

$ckbDoc = GUICtrlCreateCheckbox("doc / docx", $iLeftMargin, 90, $iItemWidth, $iItemHeight)
$ckbXls = GUICtrlCreateCheckbox("xls / xlsx", $iLeftMargin, 120, $iItemWidth, $iItemHeight)
$ckbPpt = GUICtrlCreateCheckbox("ppt / pptx", $iLeftMargin, 150, $iItemWidth, $iItemHeight)
$ckbTxt = GUICtrlCreateCheckbox("txt", $iLeftMargin, 180, $iItemWidth, $iItemHeight)
$ckbPdf = GUICtrlCreateCheckbox("pdf", $iLeftMargin, 210, $iItemWidth, $iItemHeight)
$ckbZip = GUICtrlCreateCheckbox("zip", $iLeftMargin, 240, $iItemWidth, $iItemHeight)
$ckbJpeg = GUICtrlCreateCheckbox("jpeg", 100, 90, $iItemWidth, $iItemHeight)
$ckbPng = GUICtrlCreateCheckbox("png", 100, 120, $iItemWidth, $iItemHeight)
$ckbHtml = GUICtrlCreateCheckbox("html", 100, 150, $iItemWidth, $iItemHeight)
$ckbMhtl = GUICtrlCreateCheckbox("mhtl", 100, 180, $iItemWidth, $iItemHeight)
$ckbAll = GUICtrlCreateCheckbox("Search all types", 100, 210, $iItemWidth, $iItemHeight)

GUICtrlSetState($ckbDoc, $GUI_CHECKED)
GUICtrlSetState($ckbXls, $GUI_CHECKED)
GUICtrlSetState($ckbPpt, $GUI_CHECKED)
GUICtrlSetState($ckbTxt, $GUI_CHECKED)
GUICtrlSetState($ckbPdf, $GUI_CHECKED)
GUICtrlSetState($ckbZip, $GUI_CHECKED)

GUICtrlSetState($ckbDoc, $GUI_ENABLE)
GUICtrlSetState($ckbXls, $GUI_ENABLE)
GUICtrlSetState($ckbPpt, $GUI_ENABLE)
GUICtrlSetState($ckbTxt, $GUI_ENABLE)
GUICtrlSetState($ckbPdf, $GUI_ENABLE)
GUICtrlSetState($ckbZip, $GUI_ENABLE)

Share this post


Link to post
Share on other sites



They do not show up as disabled when I run your script.

Share this post


Link to post
Share on other sites

I was compiling the wrong script. I had made a copy so I didn't overwrite the good one, and wasn't paying attention. Thank you!

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