Jump to content
Sign in to follow this  
Gimpy

Saved array and get it back

Recommended Posts

Gimpy

Sorry to ask but today Im not able to figure it out,

Could you tell me or give me a exemple to copy a 3d array in a txt file and get it back? EX:

$Array[30][2]

Func Save()

;Saved all the array in a text file

Func Load()

;Read the text file to get back the information contain in a previous array[30][2]

Thanks for all your future help

PS: Sorry if I do mistake its actually not my first language

Share this post


Link to post
Share on other sites
PsaltyDS

That's only a 2D array in your example. A 3D array would be declared something like: $Array[30][2][5]

There is no way I know of to store the memory image of an AutoIt array to a file and then read it back (smarter people my know better). You would have to pick a format for delimiters and use a text file, or perhaps some kind of DB, like SQLite, to store individual elements and then read them back to a array from there.

For a 2D example, you might store the data as text in a .CSV or .INI format, as cells in a spreadsheet, or in an SQLite database.

If you really want a 3D matrix it will get more complicated, but is still doable. The thing to remember is you will be storing the individual elements in a way that you can reassemble the data later. You will not be storing the array variable itself.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Gimpy

Thanks I was meaning a 2d array,

I will look to get more information on those option you suggest

Share this post


Link to post
Share on other sites
iamtheky

This will do so provided the array does not change dimensions

Edit: Better Functions

#include <Array.au3>

Dim $BArray[2][2]

$BArray[0][0] = " 0 , 0 "
$BArray[0][1] = " 0 , 1 "
$BArray[1][0] = " 1 , 0 "
$BArray[1][1] = " 1 , 1 "

splashoff ()

_save($BArray , "C:\test\test.txt")

_ArrayDisplay ($BArray)

$BArray[0][0] = " 9 , 9 "
$BArray[0][1] = " 9 , 9 "
$BArray[1][0] = " 9 , 9 "
$BArray[1][1] = " 9 , 9 "

_ArrayDisplay ($BArray)

$new = _load("c:\test\test.txt", $BArray)

sleep (1000)

_ArrayDisplay($new)





Func _save($SrcArray , $file)
$save = fileopen ($file , 10)
for $K = 0 to Ubound($SrcArray, 1) - 1
For $L = 0 To UBound($SrcArray, 2) - 1
filewrite ($save, $SrcArray[$K][$L] & @CRLF)
Next
Next
FileClose ($save)
EndFunc



Func _load($file, $DestArray)
$file = fileopen ($file , 0)
$J = Ubound($Destarray, 1) - 1
$i = 1
for $K = 0 to $J
$first = filereadline ($file , $i)
$second = filereadline ($file , $i + 1)
$Destarray[$K][0] = $first
$Destarray[$K][1] = $second
$i += 2
Next
FileClose ($file)
Return $DestArray
EndFunc
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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.