Jump to content

trouble with _arrayConcatenate


 Share

Recommended Posts

I have a GUI that displays computers from several  library branches, each branch listed with a different radio button.  When I make selections from a branch, click the radio button for another branch and make selections, the original selections from the previous radio button are lost.  _arrayDispaly shows  only the selections from the last radio button.  I’m assuming that I’m using _arrayConcatenate incorrectly, but the syntax for the command is pretty simple.  It appears that when I change radio buttons, my previous array is deleted.  In the end, I want to have an array with all selections made from all branches.  Thanks for your help.  This forum is a godsend.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <GuiButton.au3>


_Singleton("fcplMainGUI.au3", 0)
_Singleton("fcplMainGUI.exe", 0)

Opt("MustDeclareVars", 1)

Dim $aItems, $hpItems, $hqItems, $prItems, $sfItems, $sItems, $SourceFile, $ProgNum, $FileCopySuccess, $brSelect, $i

_Main()


Func _Main()
    Local $hListBox, $FinishButton, $CancelButton, $rdocu, $rdohp, $rdohq, $rdopr, $rdosf, $gui, $iState, $fEnable, $rdocuchk, $rdohqchk, $rdoprchk, $rdosfchk, $rdohpchk
    ; Create GUI
    $gui = GUICreate("Select OPACs", 258, 550)
    $FinishButton = GUICtrlCreateButton("Finish", 4, 490, 120)
    $CancelButton = GUICtrlCreateButton("Cancel", 128, 490, 120)
    $rdocu = GUICtrlCreateRadio("CU", 20, 525)
    $rdohp = GUICtrlCreateRadio("HP", 65, 525)
    $rdohq = GUICtrlCreateRadio("HQ", 110, 525)
    $rdopr = GUICtrlCreateRadio("PR", 159, 525)
    $rdosf = GUICtrlCreateRadio("SF", 205, 525)
    _GUICtrlButton_SetCheck($rdocu)
    $hListBox = GUICtrlCreateList("", 2, 2, 253, 496, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_EXTENDEDSEL))
    GUISetState()
    While 1
        Select
            Case _GUICtrlButton_GetCheck($rdocu) = $BST_CHECKED And $rdocuchk <> 1
                ; Add strings
                _GUICtrlListBox_BeginUpdate($hListBox)
                _GUICtrlListBox_ResetContent($hListBox)
                For $i = 1 To 5
                    _GUICtrlListBox_AddString($hListBox, "CUOPAC" & $i)
                Next
                For $i = 1 To 29
                    _GUICtrlListBox_AddString($hListBox, "CUOPACS" & $i)
                Next
                For $i = 1 To 3
                    _GUICtrlListBox_AddString($hListBox, "CUOPACEC" & $i)
                Next
                _GUICtrlListBox_EndUpdate($hListBox)
    $aItems = _GUICtrlListBox_GetSelItemsText($hListBox)

                ; Select items
                $rdocuchk = 1
                $rdohpchk = 0
                $rdohqchk = 0
                $rdoprchk = 0
                $rdosfchk = 0
            Case _GUICtrlButton_GetCheck($rdohp) = $BST_CHECKED And $rdohpchk <> 1
                ; Add strings
                _GUICtrlListBox_BeginUpdate($hListBox)
                _GUICtrlListBox_ResetContent($hListBox)
                For $i = 1 To 32
                    If $i < 10 Then $i = "0" & $i
                    _GUICtrlListBox_AddString($hListBox, "HPOPAC" & $i)
                Next
                _GUICtrlListBox_EndUpdate($hListBox)
    $hpItems = _GUICtrlListBox_GetSelItemsText($hListBox)
                ; Select items
                $rdocuchk = 0
                $rdohpchk = 1
                $rdohqchk = 0
                $rdoprchk = 0
                $rdosfchk = 0
            Case _GUICtrlButton_GetCheck($rdohq) = $BST_CHECKED And $rdohqchk <> 1
                ; Add strings
                _GUICtrlListBox_BeginUpdate($hListBox)
                _GUICtrlListBox_ResetContent($hListBox)
                For $i = 1 To 52
                    _GUICtrlListBox_AddString($hListBox, "HQOPAC" & $i)
                Next
                _GUICtrlListBox_EndUpdate($hListBox)
    $hqItems = _GUICtrlListBox_GetSelItemsText($hListBox)
                ; Select items
                $rdocuchk = 0
                $rdohpchk = 0
                $rdohqchk = 1
                $rdoprchk = 0
                $rdosfchk = 0
            Case _GUICtrlButton_GetCheck($rdopr) = $BST_CHECKED And $rdoprchk <> 1
                ; Add strings
                _GUICtrlListBox_BeginUpdate($hListBox)
                _GUICtrlListBox_ResetContent($hListBox)
                For $i = 1 To 72
                    _GUICtrlListBox_AddString($hListBox, "PROPAC" & $i)
                Next
                _GUICtrlListBox_EndUpdate($hListBox)
    $prItems = _GUICtrlListBox_GetSelItemsText($hListBox)
                ; Select items
                $rdocuchk = 0
                $rdohpchk = 0
                $rdohqchk = 0
                $rdoprchk = 1
                $rdosfchk = 0
            Case _GUICtrlButton_GetCheck($rdosf) = $BST_CHECKED And $rdosfchk <> 1
                ; Add strings
                _GUICtrlListBox_BeginUpdate($hListBox)
                _GUICtrlListBox_ResetContent($hListBox)
                For $i = 10 To 12
                    _GUICtrlListBox_AddString($hListBox, "SFOPACO" & $i)
                Next
                For $i = 1 To 12
                    _GUICtrlListBox_AddString($hListBox, "SFOPACA" & $i)
                Next
                For $i = 1 To 6
                    _GUICtrlListBox_AddString($hListBox, "SFOPACJ" & $i)
                Next
                For $i = 1 To 6
                    If $i = 2 Then $i = "2ADA"
                    _GUICtrlListBox_AddString($hListBox, "SFOPACT" & $i)
                    If $i = "2ADA" Then $i = 2
                Next
                _GUICtrlListBox_EndUpdate($hListBox)
    $sfItems = _GUICtrlListBox_GetSelItemsText($hListBox)
                $rdocuchk = 0
                $rdohpchk = 0
                $rdohqchk = 0
                $rdoprchk = 0
                $rdosfchk = 1
        EndSelect
        ; Select items
        Switch GUIGetMsg()
            Case $CancelButton
                Exit
            Case $FinishButton
                ExitLoop
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    _ArrayConcatenate($aItems, $hpItems)
    _ArrayConcatenate($aItems, $hqItems)
    _ArrayConcatenate($aItems, $prItems)
    _ArrayConcatenate($aItems, $sfItems)
    WEnd
    ; Get text of selected items
    $aItems = _GUICtrlListBox_GetSelItemsText($hListBox)
    GUIDelete()
        _ArrayDisplay($aItems)
EndFunc   ;==>_Main

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

First off, you end up blowing away the array right after you exit the While loop with your  $aItems = _GUICtrlListBox_GetSelItemsText($hListBox)  statement.  Secondly I must discourage using the _ArrayConcatenate in a loop.  That is just asking for trouble.  I'm not thinking of a more elegant solution ATM (very tired), but I'd prob approach it by acting on clicks into the listbox (add to a temp array when listbox is clicked), copy temp array to final array when radio button switched or finish button is pressed and evalutate the final array.  You are bound to get doubles if you switch back and forth between radio buttons and reselect a previously selected items, but this can be solved with _ArrayUnique.  However, I try to avoid using workarounds in lieu more effective techniques.  Better option would be to creat one array and update it dynamically based on selected or deselected items.  A bit more coding but much more efficient.

 

edit: Sorry if this is confusing or sounds like nonsense...I did say I am very tired. :wacko:

Edited by spudw2k
Link to comment
Share on other sites

Another alternative would be to utilize tabs with their own listviews instead of radiop buttons that dynamically populate a single listview.  That way the listview selections will remain. Not sure what would have better performance and don't really have the time to test.  Just thought I'd throw out the idea.

Link to comment
Share on other sites

Thanks for the replies, spudw2k.  In light of all you've said, and taking my coding skills into account, I believe I'll just make my GUI not have radio buttons or tabs, just one long scroll list of systems on the domain.  If I put public computers alphabetically first, then staff systems alphabetically, it won't be too difficult to find any particular system.  Having said that, your comment about having an item added to a temp array when the listbox is clicked sounds interesting.  Care to post a brief example of how that could be made to work?  Thanks again.

Meds.  They're not just for breakfast anymore. :'(

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