Jump to content

Help with _FileReadToArray


DeFuser
 Share

Recommended Posts

Hello all,

In one of my scripts, I have the following code:

Func CreateArray()
    Local $aTempArray
    _FileReadToArray($File, $aTempArray)

    For $iAE1 = 0 to $aTempArray[0]
        $aArray[$iAE1][0] = $aTempArray[$iAE1]
    Next
    
    Return $aTempArray[0]
EndFunc

AU3Check finds no errors.

If I run this within SciTE all is well.

If I create and run a compiled .exe from my memory stick (drive B: - where the thing was created) all is well.

If I move the .exe to another location (C:\..., Desktop, etc.) AutoIt barks with the following:

For $iAE1 = 0 to $aTempArray[0]
For $iAE1 = 0 to $aTempArray^ERROR

Error: Subscript used with non-Array variable.

Can anyone shed light on this?

Also, the only reason I have the above in a function it that I didn't want $aTempArray hanging around for the life of the .exe and figured that this would kill it when CreateArray() ended. Is my thinking right on this or is there a command to destroy a variable?

Cheers,

Def

Link to comment
Share on other sites

  • Developers

You should test the @error returned by _FileReadToArray() to make sure that _FileReadToArray() found the file and was successful.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You should test the @error returned by _FileReadToArray() to make sure that _FileReadToArray() found the file and was successful.

Wow, thank you very much. Not only was that a great idea, but you were spot-on. When moving the .exe I totally forgot about moving the original file along with it. In the future, I'll make it a point to check error flags. Thanks again! :o

Hey, if you don't mind my asking - What's your take on deleting $aTempArray? Im I going about it in the correct manner?

Wondering what it's like to be gifted,

Def

Link to comment
Share on other sites

  • Developers

Hey, if you don't mind my asking - What's your take on deleting $aTempArray? Im I going about it in the correct manner?

Not sure what you mean... see you are moving the result into a multi dim array but don't know what you mean by deleting $aTempArray.....

By the way when $aArray[$iAE1][0] is still empty you could also use redim to add dimensions to $aTempArray and use that.

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Not sure what you mean... see you are moving the result into a multi dim array but don't know what you mean by deleting $aTempArray.....

By the way when $aArray[$iAE1][0] is still empty you could also use redim to add dimensions to $aTempArray and use that.

Post import, $aTempArray holds 600+ computer names which I then migrate to a multi-dimensional array.

Once the data is transferred, I see no reason to have $aTempArray hanging out in memory. I couldn't find a way to kill it other than by making it local to a function. Is there any other way to remove unused variables?

Of course, your suggestion regarding redim (which I never even thought of) makes the entire discussion pointless (at least in this circumstance).

Once again, thanks for the pointers and the insight. :o

Cheers (and relatively new to this),

Def

Link to comment
Share on other sites

...I didn't want $aTempArray hanging around...

from the help file under DIM:

To erase an array (maybe because it is a large global array and you want to free the memory), simply assign a single value to it:

$array = 0

This will free the array and convert it back to the single value of 0.

...hope this helps...

[size="1"][font="Arial"].[u].[/u][/font][/size]

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