Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: CrAz3D on June 05, 2004, 05:57 PM

Title: File Already Open
Post by: CrAz3D on June 05, 2004, 05:57 PM
Public Sub WriteIt()
Dim iFile As Byte
On Error GoTo WriteER
iFile = FreeFile
   Open (App.Path & "\database.db") For Output As #iFile
   For i = 1 To frmDB.DB.ListItems.Count
       Print #iFile, frmDB.DB.ListItems(i).text & " " & frmDB.DB.ListItems(i).ListSubItems(1).text & " " & frmDB.DB.ListItems(i).ListSubItems(2).text
   Next i
   Close #iFile
Exit Sub
WriteER: Chat True, True, vbRed, "Database Writing Error: " & Err.Description
End Sub


Public Sub FillDB()
Dim s As String, d() As String, z As String
Dim iFile As Byte
frmDB.DB.ListItems.Clear
On Error GoTo FillER
iFile = FreeFile
   s = Dir(App.Path & "\database.db")
   If s = "" Then
       Open (App.Path & "\database.db") For Output As #iFile
       Close #iFile
   End If
Close #iFile

Open (App.Path & "\database.db") For Input As #iFile
Do Until EOF(iFile)
   Input #iFile, z
   d = Split(z, " ")
   frmDB.DB.ListItems.Add , , d(0)
       With frmDB.DB.ListItems(frmDB.DB.ListItems.Count)
           .ListSubItems.Add , , d(1)
           .ListSubItems.Add , , d(2)
       End With
Loop
Close #iFile

Exit Sub


When I try to look into my database (frmDB.DB, a listview) I recieve 'File Already Open' from the FillDB sub.  From what I've gathered, the file is not closing from the WriteIT sub.  Any ideas?
Title: Re:File Already Open
Post by: Eric on June 05, 2004, 06:31 PM
Perhaps an error is occuring while attempting to fill the database.
Title: Re:File Already Open
Post by: CrAz3D on June 05, 2004, 06:32 PM
Quote from: CrAz3D on June 05, 2004, 05:57 PM
From what I've gathered, the file is not closing from the WriteIT sub.

Hmm.......
Open (App.Path & "\database.db") For Input As #iFile
That is what is highlighted when the error occurs.  I'm sure sure how to make sure the thing is clsoed or not.
Title: Re:File Already Open
Post by: Dyndrilliac on June 05, 2004, 06:50 PM
The only thing I see that doesn't make sense is that your telling it:On Error GoTo FillERYet there is no "FillER" Section.....But that shouldn't be the cause of the problem.
Title: Re:File Already Open
Post by: CrAz3D on June 06, 2004, 12:55 AM
FillER was listed below the Exit Sub, I just didn't copy everything I guess.
Title: Re:File Already Open
Post by: Stealth on June 06, 2004, 09:59 AM
Quote from: CrAz3D on June 06, 2004, 12:55 AM
FillER was listed below the Exit Sub, I just didn't copy everything I guess.

If your On Error code is blocking notification of an error that's happening in the above code, you won't be able to debug it. Take that statement out.

Also be sure to close the file that you have open in the error handling code:

FillER:
Close #iFile
Debug.print "Error! " & Err.number & " - " Err.Description
Title: Re:File Already Open
Post by: CrAz3D on June 06, 2004, 11:57 AM
That worked Stealth, I ened up changing it all to #1, but it still worked.  Thanks.