fox
Junior Member
Posts: 52
|
Post by fox on Jan 4, 2019 5:51:19 GMT -5
Hi all, Please, I need a good suggestion: I would like to know the easiest way to save a double dimensioned array into only one file (.txt). Thanks a lot to all and bye fox
|
|
|
Post by tsh73 on Jan 4, 2019 8:07:23 GMT -5
Hello. Have a look at this. Name of array have to be hard-coded (you can use EVAL to make "save any array" routine, but there are no way for setting it)
m=4 n=5 dim a(m,n) gosub [fillArray] gosub [printArray] fname$="data1.txt" gosub [saveArray] run "notepad "+DefaultDir$+"\"+fname$
m=6 n=3 dim a(m,n) gosub [fillArray] gosub [printArray] fname$="data2.txt" gosub [saveArray] 'notice "notepad "+DefaultDir$+"\"+fname$ run "notepad "+DefaultDir$+"\"+fname$
fname$="data1.txt" gosub [readArray] gosub [printArray]
fname$="data2.txt" gosub [readArray] gosub [printArray]
end
[fillArray] for i =1 to m for j = 1 to n a(i,j)=i*10+j next next return
[printArray] print m;" rows, ";n;" columns" print "---------------------" for i =1 to m for j = 1 to n print using("###",a(i,j)); next print next print "---------------------" return
[saveArray] open fname$ for output as #1 print #1, m print #1, n for i =1 to m for j = 1 to n print #1, using("###",a(i,j)); next print #1, "" 'for a new line next close #1 print "saved as ";fname$ print "---------------------" return
[readArray] open fname$ for input as #1 input #1, m input #1, n dim a(m,n) for i =1 to m input #1, aLine$ for j = 1 to n a(i,j)=val(word$(aLine$,j)) next next close #1 print "read from ";fname$ print "---------------------" return
|
|
fox
Junior Member
Posts: 52
|
Post by fox on Jan 4, 2019 8:24:13 GMT -5
Thanks a lot. tsh73, your suggestion is very valuable for me and I will study carefully your code. But, excuse my ignorance, does what mean "Name of array have to be hard-coded "? Thanks a lot again and bye fox
|
|
|
Post by tsh73 on Jan 4, 2019 8:33:17 GMT -5
If in your program array is named a(), it should be named the same in save/load parts. So code posted will not work with an array named b() or anything other then a().
(it doesn't make a problem if you need to save/load only one array)
|
|
fox
Junior Member
Posts: 52
|
Post by fox on Jan 4, 2019 8:46:28 GMT -5
Ah, ok. Now I understand. Thanks a lot again, tsh73. And bye. fox
|
|