gregnottage Posted April 13, 2010 Posted April 13, 2010 Hi folks, I'm very new to arrays, and I'm struggling with it a bit. I'm trying to read some settings from an INI file to an array and I then want to index the list stored in the array so that the first element in the array contains the number of items in the list (am I explaining this correctly?) Here's a snip of the code I'm working on. Please could someone explain where I'm going wrong? #include <array.au3> Global $aVolLabels[1] $strSettingsIni = @ScriptDir & "\Settings.ini" $strTotalPart = IniRead($strSettingsIni, "Partitions", "Total", "") For $i = 1 to $strTotalPart _GetVolLabel($i) Next _ArrayPop($aVolLabels); Remove last empty line from array _ArrayDisplay($aVolLabels, "Volume Labels") Func _GetVolLabel($i) ;Handle Volume Labels $strVolLabel=IniRead($strSettingsIni, "Partitions", "Label" & $i, "") ;MsgBox(0, "$strVolLabel", $strVolLabel) _ArrayInsert($aVolLabels, $i-1, $strVolLabel) EndFunc The INI file contains the following: [PARTITIONS] Total=3 Label1=System Label2=Data Label3=Temp Any help or advice is welcomed! Many thanks, Greg.
Moderators Melba23 Posted April 13, 2010 Moderators Posted April 13, 2010 gregnottage, As you have the count in the ini file, just use that as the first element of your array: #include <array.au3> Global $aVolLabels[1] $strSettingsIni = @ScriptDir & "\Settings.ini" $aVolLabels[0] = IniRead($strSettingsIni, "Partitions", "Total", "") _ArrayDisplay($aVolLabels) For $i = 1 to $aVolLabels[0] _GetVolLabel($i) Next _ArrayDisplay($aVolLabels) Func _GetVolLabel($i) ;Handle Volume Labels $strVolLabel = IniRead($strSettingsIni, "Partitions", "Label" & $i, "") _ArrayAdd($aVolLabels, $strVolLabel) EndFunc Is that what you wanted? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
gregnottage Posted April 14, 2010 Author Posted April 14, 2010 Thanks Melba - sometimes the easiest solutions are just staring you in the face, eh?! Very nice - thanks very much for that. It certainly does what I need. Just out of curiosity, and for my future use and understanding of arrays, is there some way of indexing the list? I'm still trying to get my head around arrays and learning more about them. Many thanks, Greg. gregnottage, As you have the count in the ini file, just use that as the first element of your array: #include <array.au3> Global $aVolLabels[1] $strSettingsIni = @ScriptDir & "\Settings.ini" $aVolLabels[0] = IniRead($strSettingsIni, "Partitions", "Total", "") _ArrayDisplay($aVolLabels) For $i = 1 to $aVolLabels[0] _GetVolLabel($i) Next _ArrayDisplay($aVolLabels) Func _GetVolLabel($i) ;Handle Volume Labels $strVolLabel = IniRead($strSettingsIni, "Partitions", "Label" & $i, "") _ArrayAdd($aVolLabels, $strVolLabel) EndFunc Is that what you wanted? M23
Moderators Melba23 Posted April 14, 2010 Moderators Posted April 14, 2010 gregnottage, is there some way of indexing the list?I am not sure what you mean. Arrays are indexed by the element number ([0], [1], [2], etc) - what else do you need? M23 P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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