Jump to content
Sign in to follow this  
Realm

Array Error

Recommended Posts

Realm

I made an error on my orginal ini file, and so I am attempting to reset all the values to 0 again, unfortunately the script I wrote to reset my values, keeps showing me a subscript error with Dimensions exceeded with arrays associated to variable $section. I tested with _ArrayDisplay() and it correctly displays an array list, but for some reason my script does not detect the array.

Local $origin=@DesktopDir & "\CollectionVariables.ini"
Local $temp=@DesktopDir & "\temp_CollectionVariables.ini"
$sec=IniReadSectionNames($temp)
For $a=1 To $sec[0]
    $section=IniReadSection($temp,$sec[$a])
        For $b=1 To UBound($section)-1
            $data=StringSplit(IniRead($temp,$sec[$a],$section[$b],"**No Data**"),";")
            If $data="**No Data**" Then
                IniWrite(@DesktopDir & "\md_collection.ini",$sec[$a],$section[$b],"**No Data**")
            Else
                IniWrite($origin,$sec[$a],$section[$b],$data[1]&";0;0;0;0;0;0;0;0;0;0")
            EndIf
        Next
Next

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites
kaotkbliss

I did something like

$o = $name[0]

Int($o)

to get the number stored in the array into a usalble format. The array returns a string or something like that.

What you could try in your case is something like

$se=IniReadSectionNames($temp)

$sec=$se[0]

For $a=1 To Int($sec)


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
Tvern

IniReadSection returns a 2D array. You're trying to call it with a single subscript. (as if it where 1D)

Share this post


Link to post
Share on other sites
kaotkbliss

IniReadSection returns a 2D array. You're trying to call it with a single subscript. (as if it where 1D)

I didn't even catch that lol

I saw the first IniReadSectionNames then glanced over IniReadSection figuring it was another read section names.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
Realm

The Problem must lie somewhere else, for I have done similar scripts to correct ini files before, and this is the first time I have encountered this problem though.

My Original Script

Local $origin=@DesktopDir & "\CollectionVariables.ini"
Local $bu=@DesktopDir & "\bu2_CollectionVariables.ini"
Local $temp=@DesktopDir & "\temp_CollectionVariables.ini"
$sec=IniReadSectionNames($temp)
For $a=1 To $sec[0] ;<==This works just fine!
    $section=IniReadSection($temp,$sec[$a]) 
        For $b=1 To $section[0];<==This tells me 'incorrect number of subscripts or dimension range exceeded
            $data=StringSplit(IniRead($temp,$sec[$a],$section[$b],"**No Data**"),";")
            If $data="**No Data**" Then
                IniWrite(@DesktopDir & "\md_collection.ini",$sec[$a],$section[$b],"**No Data**")
            Else
                IniWrite($origin,$sec[$a],$section[$b],$data[1]&";0;0;0;0;0;0;0;0;0;0")
            EndIf
        Next
Next

Script with your suggestion implemented

Local $origin=@DesktopDir & "\CollectionVariables.ini"
Local $bu=@DesktopDir & "\bu2_CollectionVariables.ini"
Local $temp=@DesktopDir & "\temp_CollectionVariables.ini"
$sec=IniReadSectionNames($temp)
For $a=1 To $sec[0]
    $section=IniReadSection($temp,$sec[$a]) 
    $scCount=$section[0] ;<==Now This tells me 'incorrect number of subscripts or dimension range exceeded
        For $b=1 To Int($scCount)
            $data=StringSplit(IniRead($temp,$sec[$a],$section[$b],"**No Data**"),";")
            If $data="**No Data**" Then
                IniWrite(@DesktopDir & "\md_collection.ini",$sec[$a],$section[$b],"**No Data**")
            Else
                IniWrite($origin,$sec[$a],$section[$b],$data[1]&";0;0;0;0;0;0;0;0;0;0")
            EndIf
        Next
Next

now if I were to place _ArrayDisplay($section) after $section=IniReadSection($temp,$sec[$a]) It shows me a valid array

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites
UEZ

Try: For $b=1 To UBound($section) - 1 instead of For $b=1 To $section[0]

And have in mind when writing back to an ini file that $section is a 2D array!

Br,

UEZ

Edited 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Realm

IniReadSection returns a 2D array. You're trying to call it with a single subscript. (as if it where 1D)

lol, I wrote similar scripts before to fix ini files, and from the beginning, It just did'nt look like right! Thanks for pointing out my noobishness!

Thanks fore everyone jumping in to help ;)

New Code, and working!

Local $origin=@DesktopDir & "\CollectionVariables.ini"
Local $temp=@DesktopDir & "\temp_CollectionVariables.ini"
$sec=IniReadSectionNames($temp)
For $a=1 To $sec[0]
    $section=IniReadSection($temp,$sec[$a])
    For $b=1 To $section[0][0]
        $data=StringSplit($section[$b][1],";")
        IniWrite($origin,$sec[$a],$section[$b][0],$data[1]&";0;0;0;0;0;0;0;0;0;0")
    Next
Next

Edit:

And have in mind when writing back to an ini file that $section is a 2D array!

Thanks, It was late last night that I wrote it, and discovered the error, I put away til this morn to fix, and guess I was still to tired to see the what was so simple! Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.