Regravity Posted June 7, 2011 Share Posted June 7, 2011 (edited) Hi all you amazing AutoIt coders out there. I've got a small issue thats bending my head into a pretzel. I'm teaching myself to use arrays to populate ListView GUI elements (don't worry, I got that no sweat).Where my problem is reading / writing the individual values from the ini file variable in each of the columns.Perhaps a little code is called for: Main Script:expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> Global $INdirs = IniReadSection("FileTypes.ini","LISTVIEWITEMS") Global $OUTdirs = IniReadSectionNames("FileTypes.ini") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("ListView read from / write to *.ini data test", 739, 448, @DesktopWidth/2-739/2, @DesktopHeight/2-448/2) $lister = GUICtrlCreateListView("Directory From|Extension|Directory To", 8, 16, 618, 414) If @error Then MsgBox(4000, "", "Error occurred, no ini file.") Else For $i = 1 to $INdirs [0][0] GuiCtrlCreateListViewItem($INdirs[$i][1],$lister) Next EndIf GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 250) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 250) $addButton = GUICtrlCreateButton("Add Filter", 632, 16, 99, 25, $WS_GROUP) $removeButton = GUICtrlCreateButton("Remove Filter", 632, 48, 99, 25, $WS_GROUP) $exitButton = GUICtrlCreateButton("Exit", 632, 408, 99, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### TrayTip("Project Tyrion ListView Test", "Activated",10) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $addButton Case $removeButton Case $exitButton Exit EndSwitch WEndAnd Now for the INI file:;---------------------------------- ; ; FileTypes ; ;---------------------------------- [LISTVIEWITEMS] VAR1=First|zip|Second VAR2=Third|exe|Fourth VAR3=Fifth|7z|SixthOK so as you will see I've got it reading the variables (eg VAR1=First|zip|Second) but I'm really not sure how I should go about reading individual data from each variable (eg the ZIP portion of VAR1). Conversely I'd like to also write values to parts of the variable from specific text fields of a yet-to-be-developed GUI.I'm stumped for now, Regex? different sort of array?Thanks in advance! Edited June 7, 2011 by Regravity Link to comment Share on other sites More sharing options...
UEZ Posted June 7, 2011 Share Posted June 7, 2011 (edited) I would create a new 2D array with the values from the VARx which will look like the ListView. You can easily access the desired values afterwards. Br, UEZ Edited June 7, 2011 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 More sharing options...
Regravity Posted June 7, 2011 Author Share Posted June 7, 2011 Thanks for the help UEZ, Any chance of an example to get me going? Link to comment Share on other sites More sharing options...
Regravity Posted June 9, 2011 Author Share Posted June 9, 2011 Thanks for the help UEZ, Any chance of an example to get me going?*BUMP* Link to comment Share on other sites More sharing options...
ILLBeBack Posted June 9, 2011 Share Posted June 9, 2011 *BUMP* I think you’re looking for the function StringSplit, which will split the delimited INI Key data into a 1d array from which a new 2d array can be constructed where each part of the Key is in its own indices. I built upon your IF statement to do what I’ve described. If @error Then MsgBox(4000, "", "Error occurred, no ini file.") Else ;; Define a new 2d array Global $aInDirs2[$INdirs[0][0] + 1][4] For $i = 1 To $INdirs[0][0] GUICtrlCreateListViewItem($INdirs[$i][1], $lister) ;; Split the delimited string into a temporary array Local $a1 = StringSplit($INdirs[$i][1], "|") ;; Populate the new 2d array with the individual items of this INI Key. $aInDirs2[$i][1] = $a1[1] $aInDirs2[$i][2] = $a1[2] $aInDirs2[$i][3] = $a1[3] Next EndIf Link to comment Share on other sites More sharing options...
UEZ Posted June 9, 2011 Share Posted June 9, 2011 Here an example: expandcollapse popup#include <Array.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> Global $INdirs = IniReadSection("FileTypes.ini","LISTVIEWITEMS") Global $OUTdirs = IniReadSectionNames("FileTypes.ini") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("ListView read from / write to *.ini data test", 739, 448, @DesktopWidth/2-739/2, @DesktopHeight/2-448/2) $lister = GUICtrlCreateListView("Directory From|Extension|Directory To", 8, 16, 618, 414) If @error Then MsgBox(4000, "", "Error occurred, no ini file.") Else For $i = 1 to $INdirs [0][0] GuiCtrlCreateListViewItem($INdirs[$i][1],$lister) Next EndIf Global $aBackend[100][100] ;100 is just a space holder for 100 values in x and y direction Global $aTmp, $j, $y = 0 For $i = 1 To UBound($INdirs) - 1 $aTmp = StringSplit($INdirs[$i][1], "|", 2) $y = UBound($aTmp) For $j = 0 To UBound($aTmp) - 1 $aBackend[$i - 1][$j] = $aTmp[$j] Next Next ReDim $aBackend[$i - 1][$y] ;resize the array to its real dimension _ArrayDisplay($aBackend) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 250) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 250) $addButton = GUICtrlCreateButton("Add Filter", 632, 16, 99, 25, $WS_GROUP) $removeButton = GUICtrlCreateButton("Remove Filter", 632, 48, 99, 25, $WS_GROUP) $exitButton = GUICtrlCreateButton("Exit", 632, 408, 99, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### TrayTip("Project Tyrion ListView Test", "Activated",10) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $addButton Case $removeButton Case $exitButton Exit EndSwitch WEnd $aBackend holds the data which will be displayed also to the ListView control. Br, 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 More sharing options...
Regravity Posted June 13, 2011 Author Share Posted June 13, 2011 Thanks for your help IllBeBack and UEZ! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now