Valhalla Legends Forums Archive | Visual Basic Programming | File Already Open

AuthorMessageTime
CrAz3D
[code]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[/code]

[code]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[/code]

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?
June 5, 2004, 10:57 PM
LoRd
Perhaps an error is occuring while attempting to fill the database.
June 5, 2004, 11:31 PM
CrAz3D
[quote author=CrAz3D link=board=31;threadid=7112;start=0#msg63759 date=1086476234]
From what I've gathered, the file is not closing from the WriteIT sub.
[/quote]

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.
June 5, 2004, 11:32 PM
Dyndrilliac
The only thing I see that doesn't make sense is that your telling it:[code]On Error GoTo FillER[/code]Yet there is no "FillER" Section.....But that shouldn't be the cause of the problem.
June 5, 2004, 11:50 PM
CrAz3D
FillER was listed below the Exit Sub, I just didn't copy everything I guess.
June 6, 2004, 5:55 AM
Stealth
[quote author=CrAz3D link=board=31;threadid=7112;start=0#msg63804 date=1086501327]
FillER was listed below the Exit Sub, I just didn't copy everything I guess.
[/quote]

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:

[code]FillER:
Close #iFile
Debug.print "Error! " & Err.number & " - " Err.Description[/code]
June 6, 2004, 2:59 PM
CrAz3D
That worked Stealth, I ened up changing it all to #1, but it still worked. Thanks.
June 6, 2004, 4:57 PM

Search