Announcement

Collapse
No announcement yet.

Problems w/ SImple File I/O

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Guest's Avatar
    Guest replied
    Thanks Borje and Dorian,

    that was it. It seems to be very difficult drop old habits you developed in other environments.

    Thanks,

    Lasse Rantanen
    [email protected]

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Borje is right.

    Two calls to FreeFile will return the same number, unless there is an Open.. between them.


    ------------------

    Leave a comment:


  • Borje Hagsten
    replied
    Have you checked the handles you receive in the FREEFILE loop?
    My guess is you will get two identical ones there, or? Better
    to get one handle, open that file and then use FREEFILE again
    to get a handle for the next file.



    ------------------

    Leave a comment:


  • Guest's Avatar
    Guest started a topic Problems w/ SImple File I/O

    Problems w/ SImple File I/O

    Hi all,

    I have probably developed a blind spot in my eye, because I can't see why following does not work.

    Code:
    ' Create a test file
        fNo(0) = FREEFILE
     
        OPEN InFile FOR OUTPUT AS #fNo(0)
     
        FOR j = 1 TO 3000 ' Write this many random alpha records
            sTemp = ""
            FOR i = 1 TO 16 ' length of one record
                sTemp = sTemp + CHR$(RND(ASC("A"), ASC("Z")))
            NEXT
            PRINT #fNo(0), sTemp
        NEXT
     
        MSGBOX InFile + " " + STR$(LOF(fNo(0))) +" bytes"
        CLOSE #fNo(0)
     
    ' Copy test file
        FOR I = 0 TO 1
            fNo(I) = FREEFILE
        NEXT
     
        OPEN InFile FOR INPUT AS #fNo(0)
        OPEN OutFile FOR OUTPUT AS #fNo(1)
     
        ' **** Following does not work ******
        ' Nothing gets written into OutFile
        WHILE NOT EOF(fNo(0))
            LINE INPUT #fNo(0), sTemp
            PRINT #fNo(1), sTemp
        WEND
     
        CLOSE #fNo(0)
         
        MSGBOX OutFile + " " + STR$(LOF(fNo(1))) +" bytes"
        CLOSE #fNo(1)
    TIA
    Lasse Rantanen
    [email protected]
Working...
X