Results 1 to 6 of 6

Thread: Error: Append Open TextFile

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    Sydney, Nova Scotia
    Posts
    55
    Sometimes I get an error when performing this code, anyone know how to avoid this error? Trying to Append Open File


    Private Sub Save_Click()

    Dim i As Integer

    Open "events.txt" For Append As #1

    For i = 0 To Events.ListCount
    Print #1, Events.List(i)
    Next i

    For i = 0 To Players.ListCount
    Print #1, Players.List(i)

    Next i

    'Save the text from Text1 as well
    Print #1, Session.text
    Print #1, Map.text
    Print #1, MaxScore.text
    Print #1, MaxTime.text
    Print #1, MaxTons.text

    Close #1

    End Sub


    Vince McMullin
    Aka Vam, Vinny Mac

    Its just that simple

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    what is the error...is it nothing in the listindex?
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This could be the error, The listitems are starting from 0, not 1.
    Code:
    For i = 0 To Events.ListCount - 1
    Print #1, Events.List(i) 
    Next i 
    
    For i = 0 To Players.ListCount - 1
    Print #1, Players.List(i) 
    Next i
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    Sydney, Nova Scotia
    Posts
    55
    The error happens randomly and it says "Trying to Append All ready open file"

    Then it closes....... Ok If I restart my app its ok.


    The textfiles and listboxes contain information yes..... It doesn't crash if they don't either


    Basically I think that if I open events.txt (which I did) and then close that for someone reason Appen seems to think its still open after I close it.
    Vince McMullin
    Aka Vam, Vinny Mac

    Its just that simple

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Instead of #1 you should put a filenumber you know is free

    Like this:
    Code:
    Dim ff as integer
    ff=Freefile
    Open "events.txt" For Append As ff
    .
    .
    Print #ff, Events.List(i)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    I know that on occasion, I can find myself getting an error like that when I am working in a hurry and not using the FreeFile function. You might give it a try, doing something like this:

    Code:
    Private Sub Save_Click() 
    
    Dim i As Integer
    Dim FF as integer
    
    FF=FreeFile 
    
    Open "events.txt" For Append As FF 
    
    'If you loss the Next i bit and just make it Next, 
    'you will notice a speed increase on large loops.
    
    If Events.ListCount<>0 then
        For i = 0 To Events.ListCount 
            Print #FF, Events.List(i) 
        Next 
    End if
    
    If Players.ListCount<>0 then
        For i = 0 To Players.ListCount 
            Print #FF, Players.List(i) 
        Next  
    End if
    
    'Save the text from Text1 as well 
    Print #FF, Session.text & Map.text & MaxScore.text & _
               MaxTime.Text & MaxTons.Text
    
    Close FF 
    
    End Sub
    Hope this is helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width