Sign in to follow this  
Followers 0
DeFuser

Help with _FileReadToArray

7 posts in this topic

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

Share this post


Link to post
Share on other sites



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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

from the help file under DIM:...hope this helps...

Beautiful!

Now I have 2 ways to tackle issues of this type. :o

Thanks,

Def

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  
Followers 0