Click here to LOGIN
Information
Tutorials & Articles
Programs
Feedback
 


Forum
Add a Post
Username:   (You must log on to use your member username)Hint: Use [code] and [/code] around text to highlight it as QB code.


Subject:
Message:
Forums -> Q & A -> storing data
babyboomerboy
storing data
Posted Oct 11 2009
First let me say that I have been coming to this site almost every day for a year and have learned a lot about programming. My thanks to all who have been contributing here. Now this is my problem. I have a program and want to store a string of numbers and call it name. I have no problem inputing these numbers and recalling them. However, if I want to store another string of number and call it a different name, I lose the first set of data numbers. Here is the input and ouput part of my program.
rname = 0
input rname
racename.dat = rname
open "racename.dat" for output as #1
write #1, racename
print #1, aline
close #1

Then when I want to call it back I use
rname = 0
input rname
racename.dat = rname
open "racename.dat" for input as #1
input #1, racename
input #1, aline
close #1

If I make a file called 001 and then rerun the program and make a file called 002. Why do I lose file 001? I want to keep several files with different names. Any help would be appreciated.
Clippy
You should get the correct returns using one or the other.
Posted Oct 14 2009

Use LINE INPUT # for PRINT # string data.
When you PRINT # you create a line of text without quotation marks to the file. If INPUT # encounters a comma in the string you get a partial return and perhaps an EOF an error later. LINE INPUT gets the entire file line in one swoop.

The best way to do it is use WRITE # to create 2 comma separated data strings and INPUT # to read both at the same time.

WRITE #1, racename$, aline$

File data: "Health Insurance", "Aflac!"

INPUT #1, racename$, aline$

WRITE keeps the quotes around strings. PRINT does not! If you look at the file, you will see both values separated by a comma. WRITE files are also called CSV (comma separated values) that can be read using Excel spreadsheets.
babyboomerboy
Posted Oct 15 2009
Thank you Clippy for helping me with my question. I have been working on this data storing part of my program but I still erase the previous inputs when I rerun the program. When I use line input# I get an error. However the write #1, racename$, rname$ works. What I am doing is writing a program that handicapps greyhound dogs. I get the program that has past preformances for each dog and input this into my program. I have different formula's that weigh the inputs and gives me the results. The program gives me the 3 dogs that should be first, second and third in the race. I am able to correctly pick at least one dog that will be in the money over 95% of the time. I want to be able to save all the races I input so I can go back and rerun them if I tweek the formulas. Hope this help. Thanks again
Ron
PS I have been working on this program since 1983
Clippy
Where are you storing the data? One variable cannot work.
Posted Oct 15 2009
You need to put the data into an array. If you have strings and number values you'll need different arrays. Use a loop counter to assign the data indexes.

So your data reads would be:

count = count + 1
INPUT #1, racename$(count), aline%(count)

Then the program will hold all of your file data if you want.
babyboomerboy
Posted Oct 19 2009
Clippy, you are probably going to give up on me because I guess Iam to dumb to figure this out, but I still can't get the program to keep more than the last record that was inputed. My variables are already in an array, aline(x,ttp) ,time(x,ttp) and grade(x,ttp) so my first problem was how to use the count you suggested and add that into the arrayed variables that I was using. I tried using a random file, but when the program came to the third variable, grade(x,ttp) it stopped because I was out parameters. Anyway, I truely thank you for trying to help me. Some people just weren't meant for higher intellegents..
Clippy
Random files use a TYPE definition
Posted Oct 19 2009
TYPE Typename
racename AS STRING * 10 ' fixed length strings only
aline AS STRING * 10 ' use whatever length you need
END TYPE

DIM race AS Typename ' create a dot variable name

You can use any mixture of strings and number values in the TYPE. So race.racename = will hold the string value after the file is created.

Why not try my Q-Basics Demo in Member Files here and read Chapter 9. That will give you some ideas!

Ted
Clippy
Also OUTPUT mode erases everything in a file!
Posted Oct 19 2009
Use APPEND to add data to sequencial files.
Use RANDOM to add fixed length TYPE record data with PUT # and a record position. No position will overwrite previous data.

The QBasic Station, (C) Copyright 1997-2010