Jump to content

Output mutiple Listbox selections to files


Go to solution Solved by Nine,

Recommended Posts

I have run into another issue with my project... Not sure if this should be in this GUI area of the forum or another.

I am trying to get the items that are selected to create a file for each selection.  I can output a single selection to a file without issue.  I think I need some array to loop through each selection to create the files but I really do not understand arrays.  I tried looking through the array tutorial but it is over my head.  Most of the things I create are simple and do not require any array.

Any assistance is welcomed.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>


#Region ### START Koda GUI section ### Form=\\bjcsccmfr01\osd.files\_prodtsfiles\osdfrontend-v2\optionlistformtest.kxf
$Form1_1 = GUICreate("OptionListForm", 627, 437, 324, 124)
$List1 = GUICtrlCreateList("", 48, 120, 217, 266,BitOr($GUI_SS_DEFAULT_LIST, $LBS_MULTIPLESEL))
$List2 = GUICtrlCreateList("", 360, 120, 217, 266)
$Option1rdo = GUICtrlCreateRadio("Option 1", 48, 24, 73, 25)
$Option2rdo = GUICtrlCreateRadio("Option 2", 48, 56, 73, 25)
$add = GUICtrlCreateButton("add", 280, 168, 65, 33)
$clear = GUICtrlCreateButton("clear", 280, 216, 65, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $VariableFiles = "Y:\VariableFiles"
    DirCreate($VariableFiles)
GLOBAL $sOptionList = @ScriptDir & "\OptionList.txt"
GLOBAL $sOptionList2 = @ScriptDir & "\OptionList2.txt"
Global $aList
Global $sList


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Option1rdo
            GUICtrlSetData($List1, "")
            GUICtrlSetData($List2, "")
            _FileReadToArray($sOptionList, $aList, $FRTA_NOCOUNT)
            $sList = _ArrayToString($aList, "|")
            GUICtrlSetData($List1, $sList, "")
            FileOpen($VariableFiles & "Option1", 1)
        Case $Option2rdo
            GUICtrlSetData($List1, "")
            GUICtrlSetData($List2, "")
            _FileReadToArray($sOptionList2, $aList, $FRTA_NOCOUNT)
            $sList = _ArrayToString($aList, "|")
            GUICtrlSetData($List1, $sList, "")
            FileOpen($VariableFiles & "Option2", 1)
        Case $add
            _AddList()
        Case $clear
            GUICtrlSetData($List2, "", "")
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _AddList()

    Local $aList = _GUICtrlListBox_GetSelItemsText($List1)
    Local $sList = _ArrayToString($aList, "|", 1, -1)
    GUICtrlSetData($List2, $sList, "")

    If IsArray($sList) Then
        For $i = 0 to $sList[0]
            MsgBox($MB_SYSTEMMODAL, "Array Info", "Array Text: " & _GUICtrlListBox_GetText($sList[$i],1))
            FileOpen($VariableFiles & $sList[$i],1)
        Next
    EndIf

    ;These work for a single selection only....
    ;FileOpen($VariableFiles & $sList,1)
    ;MsgBox($MB_SYSTEMMODAL, "Information", "Item Text: " & $sList,1)

EndFunc

Thanks
Trinnon

Link to comment
Share on other sites

  • Solution

I think your problem is that you are using $sList as an array while it should be $aList.  

ps. it is hard to help when you do not provide a full runable snippet of your code (aka OptionList.txt files).  And you did not clarify what this code is supposed to do...

Link to comment
Share on other sites

Wow.  I cannot believe I was that close to it working.  I never tried $alist. :(
The only thing it does that I don't need is it creates a file with the number of items selected.  I can just ignore that file.


The optionlists are just text files with random words in one column.  I want to leave file names as breadcrumbs for another process to pick them up and make them variables inside an SCCM Task Sequence to install applications and set regisry tatoos.  This is just my simple sample version of the code used to troubleshoot specific issues.

 

Here is the updated code and the optionlist files.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>


#Region ### START Koda GUI section ### Form=\\bjcsccmfr01\osd.files\_prodtsfiles\osdfrontend-v2\optionlistformtest.kxf
$Form1_1 = GUICreate("OptionListForm", 627, 437, 324, 124)
$List1 = GUICtrlCreateList("", 48, 120, 217, 266,BitOr($GUI_SS_DEFAULT_LIST, $LBS_MULTIPLESEL))
$List2 = GUICtrlCreateList("", 360, 120, 217, 266)
$Option1rdo = GUICtrlCreateRadio("Option 1", 48, 24, 73, 25)
$Option2rdo = GUICtrlCreateRadio("Option 2", 48, 56, 73, 25)
$add = GUICtrlCreateButton("add", 280, 168, 65, 33)
$clear = GUICtrlCreateButton("clear", 280, 216, 65, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $VariableFiles = "Y:\VariableFiles"
    DirCreate($VariableFiles)
GLOBAL $sOptionList = @ScriptDir & "\OptionList.txt"
GLOBAL $sOptionList2 = @ScriptDir & "\OptionList2.txt"
Global $aList
Global $sList


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Option1rdo
            GUICtrlSetData($List1, "")
            GUICtrlSetData($List2, "")
            _FileReadToArray($sOptionList, $aList, $FRTA_NOCOUNT)
            $sList = _ArrayToString($aList, "|")
            GUICtrlSetData($List1, $sList, "")
            FileOpen($VariableFiles & "\Option1", 1)
        Case $Option2rdo
            GUICtrlSetData($List1, "")
            GUICtrlSetData($List2, "")
            _FileReadToArray($sOptionList2, $aList, $FRTA_NOCOUNT)
            $sList = _ArrayToString($aList, "|")
            GUICtrlSetData($List1, $sList, "")
            FileOpen($VariableFiles & "\Option2", 1)
        Case $add
            _AddList()
        Case $clear
            GUICtrlSetData($List2, "", "")
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _AddList()

    Local $aList = _GUICtrlListBox_GetSelItemsText($List1)
    Local $sList = _ArrayToString($aList, "|", 1, -1)
    GUICtrlSetData($List2, $sList, "")

    If IsArray($aList) Then
        For $i = 0 to $aList[0]
            MsgBox($MB_SYSTEMMODAL, "Array Info", "Array Text: " & $aList[$i],1)
            FileOpen($VariableFiles & "\" & $aList[$i],1)
        Next
    EndIf


EndFunc

 

Thanks,
Trinnon

OptionList2.txt OptionList.txt

Link to comment
Share on other sites

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