Jump to content

Got myself in a mess here with checkboxes


Recommended Posts

Hi all

working on a script but having problems with checboxes its supposed to calculate how much of a given item exists (eg here is music)but there will be upto 10-15 of these sections

Once its calculated i need to be able to untick one or more that i dont need the data amount for in a given job and then have it recalculate the correct amount based upon the selections

$check_1 = GUICtrlCreateCheckbox("",30,103)
    GUICtrlSetState(-1, $GUI_CHECKED)
$label_1 = GUICtrlCreateLabel( "Music Files  = ", 60, 100,150,25); this one is used for the math
$label_1a = GUICtrlCreateLabel( $music_total & "  ( " & Round($music_total /1024, 2) & "  GB )", 160, 100,350,25); this one is gui only

$music_list = _RecFileListToArray($source, $include_music, 0, 1, 0, 1, $exclude_music, $exclude_folder_music);ive omitted the includes and excludes as they are not necessary
$music_size = 0
For $i = 1 To $music_list[0]
    $music_size += FileGetSize($source & $music_list[$i]) / 1048576
Next
    ;$music_total = Round($music_size , 2) & "  Mb" this is how i origanally calculated each item and works fine

If $Check_1 = GuiCtrlRead($GUI_UNCHECKED) Then ;this is the new attempt and will either be 0.00 or the amount of data
    $music_total = 0.00 & "  Mb"
Else
    $music_total = Round($music_size , 2) & "  Mb"
EndIf


$SubmitButton = GuiCtrlCreateButton(" ReCalculate ", 115, 450); button for the recalculate

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $SubmitButton
        $Check_Status1 = GuiCtrlRead($Check_1)
        $Check_Status2 = GuiCtrlRead($Check_2)
        $Check_Status3 = GuiCtrlRead($Check_3)
        $Check_Status4 = GuiCtrlRead($Check_4)
        $Check_Status5 = GuiCtrlRead($Check_5)
    EndSwitch
WEnd

Thanks for any help to sort this out

Chimaera

Edited by Chimaera
Link to comment
Share on other sites

I would save the checkbox id's into an array because an array is much more flexible than any variable.

Further it is much easier to check all the checkboxes from an array.

To check whether a checkbox is checked you can use

$check = BitAND(GUICtrlRead($aChkbox_ids[1]), $GUI_CHECKED)

$aChkbox_ids is an array which includes the ids. If it is checked the $check will be True or 1.

Maybe this link is also helpful for you:

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thats where i started from with this one here

I did look at your examples Uez but couldn't grasp how they would work in my example as they are very complicated

Ill have a play with BitAND and see what happens

Thx again

EDIT

Ok ive added this for the checkbox creation

Global $Programs[6][2] = [[5, 2],["Music Files", 93],["Mail Files", 118],["Word Files", 143],["Excel Files", 168],["Gps Files", 193]]
Global $Checkbox[$Programs[0][0] + 1]
For $i = 1 To $Programs[0][0]
    $Checkbox[$i] = GUICtrlCreateCheckbox($Programs[$i][0], 30, $Programs[$i][1], 180, 35)
Next

How do i get this to respond to the button ?

Edited by Chimaera
Link to comment
Share on other sites

Ok still having probs with this

This is what ive got atm

;creation of checkbox array
Global $data_types[6][2] = [[5, 2],[" Music Files ", 93],[" Mail Files ", 118],[" Word Files ", 143],[" Excel Files ", 168],[" Gps Files", 193]]
Global $check_array[$data_types[0][0] + 1]
For $i = 1 To $data_types[0][0]
    $check_array[$i] = GUICtrlCreateCheckbox($data_types[$i][0], 30, $data_types[$i][1], 100, 35)
Next
;the search for the files and add to array there is more than one of these obviously

$music_list = _RecFileListToArray($source, $include_music, 0, 1, 0, 1, $exclude_music, $exclude_folder_music);ive omitted the includes and excludes as they are not necessary
$music_size = 0
For $i = 1 To $music_list[0]
    $music_size += FileGetSize($source & $music_list[$i]) / 1048576
Next
    $music_total = Round($music_size , 2) & "  Mb" ;this is how i origanally calculated each item and works fine

$SubmitButton = GuiCtrlCreateButton(" ReCalculate ", 115, 450)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $SubmitButton
            For $x = 0 to 6
                If GUICtrlRead($check_array[$i]) = $GUI_CHECKED Then
                    $label_total = $music_total + $mail_total + $word_total + $excel_total + $gps_total
        EndIf
            Next
EndSwitch
WEnd
it does the first bit until i press the button to add together the CHECKED items to give me a total then it throws an error

(164) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If GUICtrlRead($check_array[$i]) = $GUI_CHECKED Then

If GUICtrlRead(^ ERROR

->08:24:25 AutoIT3.exe ended.rc:1

>Exit code: 1 Time: 25.353

The checkboxes should either be checked = amount of data or unchecked = 0 or excluded from total

Hope someone can see whats wrong, or what ive missed

Chimaera

Link to comment
Share on other sites

  • Moderators

Chimaera,

I would put the the subtotals of the various types of file into an array and then add them to the overall total if the corresponding checkbox is checked. Here is a short example: :>

#include <GUIConstantsEx.au3>

Global $data_types[6][2] = [[5, 2],[" Music Files ", 93],[" Mail Files ", 118],[" Word Files ", 143],[" Excel Files ", 168],[" Gps Files", 193]]
Global $check_array[$data_types[0][0] + 1]
Global $aTotals[$data_types[0][0] + 1] ; This holds the subtotals for each type

$hGUI = GUICreate("Test", 500, 500)

;creation of checkbox array
For $i = 1 To $data_types[0][0]
    $check_array[$i] = GUICtrlCreateCheckbox($data_types[$i][0], 30, $data_types[$i][1], 100, 35)
Next

$SubmitButton = GUICtrlCreateButton("Submit", 10, 10, 80, 30)

GUISetState()

; Set the elements of $aTotals to the subtotals for each type of file - here we simulate this
$aTotals[1] = 1
$aTotals[2] = 10
$aTotals[3] = 100
$aTotals[4] = 1000
$aTotals[5] = 10000

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $SubmitButton
            ; Reset the overall total 
            $label_total = 0
            For $i = 1 to $data_types[0][0]
                ; Look if checkbox checked
                If GUICtrlRead($check_array[$i]) = $GUI_CHECKED Then
                    ; Add subtotal to the overall total
                    $label_total += $aTotals[$i]
                EndIf
            Next

            ; Now display the result so you can see only the checked totals were added
            ConsoleWrite($label_total & @CRLF)

    EndSwitch
WEnd

All clear? :unsure:

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

Thanks again for the help Melba23

that bit is working well and im sort of getting my head round it

Something else occured to me that i thought i would ask about

Is it possible to reuse an array once created?

I was trying this

$include_backup = "*.*"
$exclude_backup = "thumbs.db;ntuser.dat;NTUSER.DAT;One Step Beyond.wma;Symphony_No_3.wma;aaw7boot.log"
$exclude_folder_backup = "$Recycle.Bin;Boot;MSOCache;Program Files;Program Files (x86);Terminal Server Client;InstallShield Installation Information;Redist;HP;FOUND.???"
;~
$backup_list = _RecFileListToArray($source, $include_backup, 0, 1, 0, 1, $exclude_backup, $exclude_folder_backup)
;~
$backup_size = 0
For $i = 1 To $backup_list[0]
    $backup_size += FileGetSize($source & $backup_list[$i]) / 1048576
Next
    $subotals = Round($backup_size , 2) & "  Mb"
$backup_label = GUICtrlCreateLabel("Total Backup = " & $subotals & "  ( " & Round( $subotals /1024, 2) & "  GB )", 40, 100,350,25);<<< works fine up to here

;//////////////////////////////////////////////////////////////////////////////////////////////////////
$include_music = "*.aiff;*.alac;*.dct;*.flac;*.mpc;*.mp3;*.ogg;*.ra;*.rm;*.wma;*.nfo"
$music_list = _ArrayFindAll( $backup_list, $include_music )
_ArrayDisplay($music_list);<<<<<<<<<<<<< this was just trying to see what it was showing
ConsoleWrite($music_list & @CRLF);<<<<<<<<<<<<< this was just trying to see what it was showing
$music_size = 0
For $i = 1 To $music_list[0]
    $music_size += FileGetSize($music_list[$i]) / 1048576
Next
    $aTotals = Round($music_size , 2) & "  Mb"
$label_1a = GUICtrlCreateLabel( $aTotals & "  ( " & Round($aTotals /1024, 2) & "  GB )", 160, 125,350,25)
;//////////////////////////////////////////////////////////////////////////////////////////////////////


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

what i was trying to do was search for all files less exclusions then reuse array $backup_list from the first time and then search again in that array just for the files i wanted for the music which should reduce my search times as i am only searching the array of possible files. and creating in a sense a sub array that holds just that info?

which i can then use later for checkbox selection, using the method you showed me earlier

Any thoughts on what i have done wrong?

Chimaera

update

Been messing with this for a while

using this

$music_list = _ArraySearch( $backup_list, "mp3")
_ArrayDisplay($backup_list, "all");<<<<<<<<<<<<< this one is fine and shows the array
_ArrayDisplay($music_list, "music");<<<<<<<<<<<< this one never appears
ConsoleWrite($music_list & @CRLF);<<<<<<<<<<<<<< this one always shows -1 which is @error

tried this as well

For $i = 1 To $backup_list[0]
    If StringRegExp($backup_list[$i], "*.mp3") Then
        $music_list = $i
        ExitLoop
    EndIf
Next

dunno what the hell im doing wrong

Edited by Chimaera
Link to comment
Share on other sites

Spent a few hours on this now and still cant get it working

Using Melba's udf to give me the files like this

$backup_list = _RecFileListToArray($source, $include_files, 0, 1, 0, 1, $exclude_files, $exclude_folder)

I know the data is present from

_ArrayDisplay($backup_list, "all")
as that works, but i cant find a way to sort the data again to give me another variable

As i understand it either of these should work

$music_list = _ArraySearch( $backup_list, "*.mp3");<<< and ive tried ".mp3" and "mp3"

$include_music = "*.aiff;*.alac;*.dct;*.flac;*.mpc;*.mp3;*.ogg;*.ra;*.rm;*.wma" ;<<< not sure if this is right with the ";" inbetween them
$music_list = _ArraySearch( $backup_list, $include_music)

which should then give me the variable

$music_list
which i can use for other things

I have tried

_ArrayBinarySearch
_ArraySearch
_ArrayFindAll

and all return -1 which is doing my head in as they should work.

I have searched through the forum and the help file, i even tried converting data to a .txt file and reading it again to no avail

Can someone tell me what it is im doing wrong plz, and maybe give me a simple example?

Chimaera

Edited by Chimaera
Link to comment
Share on other sites

  • Moderators

Chimaera,

It looks to me as if you do not understand what _ArraySearch does. You seem to think that it will return a sub-array of the initial array. In fact, all you get as a return is the index of the first element within the search bounds that holds the value you are searching for. :D

Your suggested line:

$music_list = _ArraySearch( $backup_list, "*.mp3")

will almost certainly return -1 (as you have discovered), probably with with @extended set to 6 = not found. This is because there is no element in the array which actually reads "*.mp3". You could use _ArrayFindAll to determine all elements which contain ".mp3" (note the absence of the leading * wildcard) but you would still end up with a list of indices, not a subarray of the elements themselves. ;)

If you are looking to get a subset of the complete array holding only the "*.mp3" files then I would suggest the best way to go about it is to rerun the _RecFileListToArray function using an $include_files parameter of just "*.mp3". Or you could loop through a copy of the larger array and delete every element which does not contain the .mp3 extension (using StringInStr to determine this) - however as the _ArrayDelete function uses ReDim each time it is called, I am pretty certain that this would be very much slower than just rerunning the search. :unsure:

Does that help? Please ask again if anything is unclear. :>

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

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...