Jump to content

Array problem


Dura
 Share

Recommended Posts

I have a problem with a function and array, it worked for a while and then stoped and now gives me: Subscript used with non-Array variable

I've looked at this code over and over now and i must miss something so i'll post it and see if someone can help me.

Func _CountIni()
    Local $ini = @ScriptDir & "\settings.ini"
    Local $counter = 0
    If Not @error Then
        $sections = IniReadSectionNames($ini)
        For $i = 1 To $sections[0]
            $section = IniReadSection($ini, $sections[$i])
            $counter = $counter + $section[0][0]
        Next
    EndIf
    Return $counter
EndFunc

I get:

Subscript used with non-Array variable

$counter = $counter + $section[0][0]

$counter = $counter + $section^ ERROR

IniReadSection() is returning 2D array, im blind here please give me some pointers

Link to comment
Share on other sites

it should be

$counter = $counter + $section[0]

Why do you say it is returning a 2D array?

Also, your counter doesn't make sense. Each time it loops through add the number of sections there are? If you have 5 sections the counter will go 0 5 10 15 20...

Regards,Josh

Link to comment
Share on other sites

"Success: Returns a 2 dimensional array where element[n][0] is the key and element[n][1] is the value. "

Total values under that section is element[0][0]

my function do just as you say it counts the total of values in the ini over all sections

This should make it more logical:

Func _CountIni()
    Local $ini = @ScriptDir & "\settings.ini"
    Local $counter = 0
    If Not @error Then
        $sections = IniReadSectionNames($ini)
        For $i = 1 To $sections[0]
            $values = IniReadSection($ini, $sections[$i])
            $counter = $counter + $values[0][0]
        Next
    EndIf
    Return $counter
EndFunc

Edit:

Found my problem , IniReadSection() returns error hence not giving array

Edited by Dura
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...