Dura Posted August 8, 2008 Share Posted August 8, 2008 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 More sharing options...
JFee Posted August 8, 2008 Share Posted August 8, 2008 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 More sharing options...
Dura Posted August 8, 2008 Author Share Posted August 8, 2008 (edited) "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 August 8, 2008 by Dura Link to comment Share on other sites More sharing options...
JFee Posted August 8, 2008 Share Posted August 8, 2008 Sorry I read the original code you posted wrong But yeah, works fine for me with a dummy INI, I bet your INI is messed up Regards,Josh Link to comment Share on other sites More sharing options...
Dura Posted August 8, 2008 Author Share Posted August 8, 2008 yeah found the fault, had one section with no values, really need to get better at error management =) 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