Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prevent From Opening (VB6)

    Is there a way to prevent multiple instances of an application being opened at once.

    I've just checked the workshop machine and my application is sitting in the start bar 3 times.
    Obviously one user is not exiting properly.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prevent From Opening (VB6)

    That is rather technical - see HOWTO: Prevent Multiple Instances of a 32-bit VB Application. I hope you can use it.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent From Opening (VB6)

    Hans

    In the instructions :Go into Project Properties and set the Startup Object (or Startup Form in VB4) to be Sub Main.

    On changing the startobject to "Sub Main" (What is Sub Main ??), when running the application I get an error saying Stating
    "Must Have Startup or Main"

    If I set my startup to frmSplash, as it was before, I am able to make the EXE.
    Should I be calling the module from frmSplash, or should I add code into the module "Module1" to call frmSplash.

    Whichever way, "Sub Main" is not recognised.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prevent From Opening (VB6)

    Dave,

    Here are instructions for a simpler, less sophisticated way of doing it:
    <UL><LI>Note which form is the startup form of your application. You can check this in Project | <project> Properties...
    The "Startup Object" combo box displays the name of the startup form. Close the Properties dialog for the moment.
    <LI>Select Project | Add Module
    <LI>In the new module, enter the following code:

    Sub Main()
    If App.PrevInstance = False Then
    Form1.Show
    End If
    End Sub

    Replace Form1 by the name of your startup form.
    <LI>Select Project | <project> Properties... again, and change the startup object to Sub Main.
    <LI>Click OK.
    <LI>Create a new .exe.[/list]This simplified version simply ignores attempts to start a second instance of your application. You don't need the code from the MSKB for this. The code from the MSKB article does a bit more: if the application is already running, trying to start a new instance switches the user to the running instance.

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent From Opening (VB6)

    Hans

    Clear
    Precise
    Understandable
    (Now I understand "Sub Main()")

    Why couldn't Microsoft do it this way.

    Thanks again.

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Prevent From Opening (VB6)

    VB is a developer product, Dave. If they made it easy, anyone could use it. <img src=/S/innocent.gif border=0 alt=innocent width=20 height=20>
    Charlotte

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent From Opening (VB6)

    Yes Charlotte, quite correct, but sometimes the help files are not always so easy to follow ! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent From Opening (VB6)

    Hans
    I reverted back to the Microsoft example because the application with your code (Not that there's anything wrong with it) didn't restore the open form as the MS version does.
    My application is called from a command button on an Access Database in the workshop.
    When the user tried to open a second version, albeit another instance was not allowed, so good so far, but.
    The application was hidden behind the database with no way to get at it.
    I implemented the MS example, which I have running fine, but when the application is restored, the form doesn't restore itself to a
    maximised state.

    The forms windowstate is Maximised in properties, so each time it is called " frm1024Image.Show ", it opens maximised.
    On restore from the Sub Main; ActivatePrevInstance, it doesn't fill the entire screen which I had envisaged.

    Is there an edit which will envoke the Windowstate property ?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prevent From Opening (VB6)

    If there are no replies, I'll look at it tomorrow; I don't have VB6 on the PC I'm using at the moment.

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent From Opening (VB6)

    Hans
    As I stated last week, "stare long enough .............. "

    <pre>Private Sub Form_Resize()
    If Me.WindowState = 0 Then
    Me.WindowState = 2
    End If

    End Sub</pre>


    Allows the form to be minimized but if windowstate on restore = 1 then the form maximised.
    Works well with the MS article.

    <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20> <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

Posting Permissions

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