Liberty BASIC Community Forum
« Output Data (This problem is crazy) »

Welcome Guest. Please Login or Register.
Feb 18th, 2018, 3:39pm


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


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Output Data (This problem is crazy)  (Read 77 times)
Chester
New Member
Image


member is offline

Avatar




PM


Posts: 12
xx Output Data (This problem is crazy)
« Thread started on: Feb 10th, 2018, 11:12pm »

dim folks$ (5)
print " Enter up to (5) names."
print " A zero or blank entry ends the input."
index=1

[rightOn]
print " Entry "; index
input " Key in folks's name:"; folksName$
if folksName$ = "" then [endSeries]
if folksName$ = "0" then [endSeries]

folks$(index) = folksName$
index = index + 1
if index < 5 then [rightOn]

[endSeries]
xxxcount = index -1
if xxxcount = 0 then print "No entries. " : end
print "Entries completed."
print
print "---------------------------------------"
for index = 1 to xxxcount
print folks$(index)
next index

'open "cgjwmp.dat" for output as #xxxcg
for index = 1 to xxxcount
print folks$(index)
print #xxxcg, folks$(index)
next index
close #xxxcg
end
'****************************************
This is the last time I will be posting this issue.
It will be really nice if someone have more experience then me would post a solution to this little program (or) any other way to INPUT & OUTPUT and save data?

1. When I run this little program I am coming up with this error message: Invalid file handle: #xxxcg (see log)
2. This little program will output & display (5) names but will not show or display but (4) names when input (reading)
3. I am trying to do all the examples in Carl Gundel beginning programming with liberty book.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5655
xx Re: Output Data (This problem is crazy)
« Reply #1 on: Feb 11th, 2018, 01:44am »

What page of the book is this particular exercise on? I had 6 in my code you put 5 and I forgot to unrem the open file statement, so take the away from the front of that line.

I will read the exercise and make sure we are getting the right answer.

It would help get better responses if you told us right up front you are working on the book and what page you are on.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5655
xx Re: Output Data (This problem is crazy)
« Reply #2 on: Feb 11th, 2018, 02:00am »

I see it is on page 94. As I read it I see a bug as when writing to the file at the bottom of the page Carl starts with index = 1 whereas all times befor he has started with index = 0

So in the code as printed it will not save person$(0) perhaps he wanted you to find this bug?.

I will write some code a little later.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5655
xx Re: Output Data (This problem is crazy)
« Reply #3 on: Feb 11th, 2018, 02:49am »

Code:
'this is your example as indexed in the book
'the book uses a zero based index starting at 0
'not 1

dim folks$ (5)
print " Enter up to (5) names."
print " A zero or blank entry ends the input."
'we start with index undefined
'it therefor has a value of 0

[rightOn]
'we will not confuse the user by saying
'index 0 we will tell him it is index 1
print " Entry "; index + 1
input " Key in folks's name:"; folksName$
if folksName$ = "" then [endSeries]
if folksName$ = "0" then [endSeries]
'now save the name to the array at index 0
folks$(index) = folksName$
'increase the index
index = index + 1
'loop back if we are not at the final one
if index < 5 then [rightOn]
'now index is at 5,we did not store anything in 5

[endSeries]
xxxcount = index
if xxxcount = 0 then print "No entries. " : end
print "Entries completed."
print
print "---------------------------------------"

'so we want to start at 0 but we dont want to end at
'5 so...
for index = 0 to xxxcount-1
    print folks$(index)
next index

open "cgjwmp.dat" for output as #xxxcg
'same fix here we want 0-4
for index = 0 to xxxcount-1
    print folks$(index)
    print #xxxcg, folks$(index)
next index
close #xxxcg
end

 
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