saving and restoring array to and from text file

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
Anand
Posts: 595
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

saving and restoring array to and from text file

Post by Anand »

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 294 times
Regards,

Anand

Image
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: saving and restoring array to and from text file

Post by PeteWG »

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: 595
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: saving and restoring array to and from text file

Post by Anand »

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
Regards,

Anand

Image
Post Reply