Liberty BASIC Community Forum
« Why the array is not written to file ? »

Welcome Guest. Please Login or Register.
Nov 24th, 2017, 10:53am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Why the array is not written to file ?  (Read 191 times)
Zabo
Full Member
ImageImageImage


member is offline

Avatar

Yes. It work's. ha


PM

Gender: Male
Posts: 125
xx Why the array is not written to file ?
« Thread started on: Aug 12th, 2016, 09:12am »

Hi ,

i have here a testcode for writing and reading a
one dimensional array into a textfile with the
commands output and input.

Don't know why the data is not written to the file.
There are no error messages.
The data "Hello" "World" is not printed to mainwin.


Rem sequential file write and read

5 dim data$(10)

10 data$(1) = "Hello"
20 data$(2) = "World"


900 index2 = 1
910 open "bank.txt" for output as #1
920 while EOF(#1)= 0
930 print #1, data$(index2)
940 index2 = index2 + 1
950 wend
960 close #1

999 index3 = 1
1000 open "bank.txt" for input as #1
1010 while EOF(#1)= 0
1020 line input #1, data$(index3)
1030 index3 = index3 + 1
1040 print data$(index3)
1050 wend
1060 close #1

1070 end



Regards
Zabo
« Last Edit: Aug 12th, 2016, 09:15am by Zabo » User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2833
xx Re: Why the array is not written to file ?
« Reply #1 on: Aug 12th, 2016, 09:48am »

Testing for EOF is only done when reading. When you write file it is always at the end of file when you open a file for output and print to it.

Try this:
Code:
910 open "bank.txt" for output as #1
920 for index2 = 1 to 10
930 print #1, data$(index2)
940 next index2
960 close #1
 
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
Zabo
Full Member
ImageImageImage


member is offline

Avatar

Yes. It work's. ha


PM

Gender: Male
Posts: 125
xx Re: Why the array is not written to file ?
« Reply #2 on: Aug 12th, 2016, 10:19am »

Thank you Carl , i will try.

At the moment i learn file handling and database.

Best Regards

Zabo
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls