Jump to content

Recommended Posts

Posted

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
Posted

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

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

 

Posted

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
Posted

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

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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...