Qbasicnews.com

Full Version: File error loading into parallel arrays...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The OPEN file command in my code gives me an bad file error. The file path is fine, the file name is fine. I thought my open statement was correct, but I'm probably wrong. Can someone tell me what I'm doing wrong? (My data file is sequential and has four fields.) Please help!

Code:
DIM atmcount AS SINGLE
DIM Anam(20) AS STRING * 15
DIM Aact(20) AS STRING * 10
DIM Abal(20) AS SINGLE
DIM Apin(20) AS SINGLE
atmcount = 0

OPEN "a:\file.txt" FOR INPUT AS #Atmfile
DO WHILE atmcount < 20 AND NOT EOF(Atmfile)
atmcount = atmcount + 1
INPUT #Atmfile, Anam(atmcount)
INPUT #Atmfile, Aact(atmcount)
INPUT #Atmfile, Apin(atmcount)
INPUT #Atmfile, Abal(atmcount)
LOOP
CLOSE #Atmfile
It needs to be at least 1. You can do

Atmfile = FREEFILE

if you want your program to automatically find the next available file number. (And it might be "FREFILE" or some other such thing. I haven't used it in a while.)
So do I DIM it as a string and give it a value (atmfile = 1)?

UPDATE:

Where exactly would I do that? At the top of my program, in my declarations? Or with the OPEN command itself?
but just in case, Atmfile should be a numeric variable (INTEGER works real well).
It works, it works! Thanks much!
.
File handles should always be positive and not equal to zero.

Glenn: always those periods... Wink
:
er... lol 8)


@
A thing I noticed a while ago.... when he posts a period, try looking at the post SUBJECT. It's not just a gag, but a way of doing the old * trick on those hierarchial boards like neozones.