saving and restoring array to and from text file

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
Anand
Posts: 381
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 102 times
Been thanked: 52 times

saving and restoring array to and from text file

Post by Anand » Tue Jun 18, 2019 10:17 am

I have been using a very old clipper code for saving and restoring array to and from text file. It auto recurse itself if array is multidimensional. I have found it useful still in Xbase++ and HMG codes.

I have attached the same as it may be useful to members requiring the same.

Regards,

Anand
Attachments
SaveArray.zip
(1.52 KiB) Downloaded 48 times
Image

PeteWG
Posts: 141
Joined: Sun Mar 21, 2010 5:45 pm
Has thanked: 11 times
Been thanked: 45 times

Post by PeteWG » Wed Jun 19, 2019 10:31 am

Good code, in good old Clipper! ;-)
Luckily, an even better successor has followed.
FYI, Harbour includes a very powerful pair of functions,
with which you can achieve exactly the same functionality,
but with only two lines of code, although, If you're less "brave"
and more cautious, you might want to add two more lines for error-checking.

here is:

Code: Select all

//save array
hb_MemoWrit( "arr.txt", hb_Serialize( aArray ) )
// restore
aArray := hb_Deserialize( hb_MemoRead( "arr.txt" ) )
(it's amazing to see how evolution can make programmer's life easier,
although, the opposite is some times true also, unfortunately...)

regards,
Pete

User avatar
Anand
Posts: 381
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 102 times
Been thanked: 52 times

Post by Anand » Wed Jun 19, 2019 4:23 pm

Hi Pete, thanks for the tip.

The difference is that hb_Serialize output is non-human readable but can handle all types.
Though it does not matter if read/save is done by computer. Only if we need to check the values, say in a backup folder.
Now same Serialize logic is available in different language platforms and I use it.

I wanted array to save in something human readable, but obviously it can handle only standard types.

Regards,

Anand
Image

Post Reply