Jump to content
Sign in to follow this  

Using FileReadToArray ??

Recommended Posts

Can someone tell me what I'm doing wrong? I'm have the code below look in an INI file and pull out the first 8 computer names listed. The code then put that name into a $label on the GUI. It works fine if the INI has 8 or less computer name, but sometimes it will have more. This is when the code errors out. (show below)

Error: array variable has incorrect number of subscripts

Global $Label[9] = [8]

Dim $aRecords
Dim $item
If Not _FileReadToArray($Cache_Folder & "\XXXX.ini",$aRecords) Then

For $x = 1 to $aRecords[0]
    $NewStr = StringReplace($aRecords[$x],'"','')
    GUICtrlSetData($Label[$x],$NewStr )


Share this post

Link to post
Share on other sites

Well, you've pretty much spelled the whole thing out yourself...

You've a set number of labels (9, numbered 0 through 8) and you have a variable length ini file to load into the labels. As soon as the line-count of the ini exceeds the last defined label, blam, there is no $Label[9].

So, you could limit your loop, maybe add something like "If $aRecords[0] > 8 then $aRecords[0] = 8" before the loop. That would limit the load to only loading the first 8 lines form the .ini. Or, you could load $aRecords first, and then use the value of $aRecords[0] to define an array of labels matching the size of the ini file.

Anyway... me thinks you already were on the verge of your own answer.

Share this post

Link to post
Share on other sites

that worked... Thanks!!!

This was my try with arrays.

If $aRecords[0] > 8 then $aRecords[0] = 8

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...