[RESOLVED] Problems with multiple form instances and writing files
Hi,
I have a form with a Inet control, for downloading some files listed in a MSHFlexgrid. That runs totally fine until I decided to have multiple instances of this form. When the app is ready to open the file for writing, I have a error 55 "File already open".
My download function is defined on the form, and this is where the error occurs:
Code:
Public Function Download(ArqURL As String, Arqtemp As String) As Boolean
'(...)
Open Arqtemp For Binary Access Write As #1
'(...)
and this is how I'm creating a new instance of the form:
Code:
Private Sub ger_Click()
Dim x As New MainForm
x.Show
End Sub
My question now is: if I create a new instance of the form, why is there a conflict with the "Download" function (which is defined in the form) and how can I solve this issue?
Many thanks
;)
Re: Problems with multiple form instances and writing files
Don't use hardcoded file numbers (i.e., #1, #2, etc). Use VB's FreeFile() function to return an available file handle. Of course you should be using a method of ensuring you are also writing to unique file names also.
Re: [RESOLVED] Problems with multiple form instances and writing files
Thanks. Using "FreeFile" solved my problem.