Results 1 to 3 of 3

Thread: [RESOLVED] Problems with multiple form instances and writing files

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Resolved [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

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [RESOLVED] Problems with multiple form instances and writing files

    Thanks. Using "FreeFile" solved my problem.

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