Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
file I/O
#1
im having a problem with file I/O. i dont really know whats wrong but here is the code:

Code:
...
OPEN "array.txt" FOR OUTPUT AS #1"
FOR z = LBOUND(array) TO UBOUND(array)
  WRITE #1, array(z).part1, array(z).part2
NEXT z
CLOSE #1
...
OPEN "array.txt" FOR INPUT AS #1"
FOR z = LBOUND(array) TO UBOUND(array)
  INPUT #1, array(z).part1, array(z).part2
NEXT z
CLOSE #1

FOR z = LBOUND(array) TO UBOUND(array)
  PRINT array(z).part1
  PRINT array(z).part2
NEXT z
...

this only prints spaces where it should print the variables. if this isnt enough information, i can post more code, just say so

thanks! Big Grin
Reply
#2
This works:

Code:
CLS
TYPE type2
a2 AS INTEGER
b2 AS INTEGER
END TYPE

DIM a(1 TO 5) AS type2
OPEN "temp.txt" FOR OUTPUT AS #1

FOR i = LBOUND(a) TO UBOUND(a)
a(i).a2 = i: a(i).b2 = i + 1
NEXT

FOR i = LBOUND(a) TO UBOUND(a)
WRITE #1, a(i).a2, a(i).b2                 'PRINT also works
a(i).a2 = 0: a(i).b2 = 0
NEXT
CLOSE

OPEN "temp.txt" FOR INPUT AS #1
FOR i = LBOUND(a) TO UBOUND(a)
INPUT #1, a(i).a2, a(i).b2
PRINT a(i).a2, a(i).b2
NEXT

If it doesn't really help post more >^-^<
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
thanks for helping Smile

unfortunately though it still doesnt work

these are some things that might affect it:

1. the array holds strings, not integers
2. it is writing to the file, because the stuff was there when i looked. however, before the strings, there were strings with all spaces there. maybe that could affect it
3. does the print statement have to be directly after the input # because it isnt in my program, that may do it

if this still isnt enough ill just post the whole program (or most of it because its pretty long for a post)

thanks Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)