check if application is already opened
My first VB6 project!
but my first very big prob!
I have compiled my project with name MYPrg.exe.
Now if a user re-click on the icon "MYPrg" the user open twice the app!!!!
Is possible if the application MYPrg.exe is already opened, appear a Msgbox (Attention the application is alredy run on this PC)...
How to?
Re: check if application is already opened
Use app.prevInstance in the startup section of your app:
Code:
If App.PrevInstance Then ' insert your code to exit gracefully
1 Attachment(s)
Re: check if application is already opened
Quote:
Originally Posted by
Witis
Use app.prevInstance in the startup section of your app:
Code:
If App.PrevInstance Then ' insert your code to exit gracefully
ok tks...
I use this in Form_Load event of main form:
Code:
If App.PrevInstance Then
MsgBox "Application already active!", vbInformation
Unload Me
End If
but when i click OK on msgbox i have this error in image:
Re: check if application is already opened
That is definitely not the Application already active! msgbox you added, so you will need to step through your startup code to trace the error.
To step through your code:
1. Insert a stop point. Left click in the margin to the left of a line of code in your startup procedure. You will be able to see a red dot indicating a stop point is visible.
2. Then run your application. It will stop at the break point you just created.
3. Now step through your code a line at a time using the F8 button. Note you can use shift + F8 to skip over a call to a subroutine or a function.
Don't forget to remove the stop point when you have finished by left clicking the red dot you created in the margin.
Re: check if application is already opened
Quote:
Originally Posted by
Witis
That is definitely not the Application already active! msgbox you added, so you will need to step through your startup code to trace the error.
To step through your code:
1. Insert a stop point. Left click in the margin to the left of a line of code in your startup procedure. You will be able to see a red dot indicating a stop point is visible.
2. Then run your application. It will stop at the break point you just created.
3. Now step through your code a line at a time using the F8 button. Note you can use shift + F8 to skip over a call to a subroutine or a function.
Don't forget to remove the stop point when you have finished by left clicking the red dot you created in the margin.
Tks! But i have resolved with:
Code:
Private Sub Form_Load()
If App.PrevInstance Then
MsgBox "APPLICAZIONE *** " & App.Title & " *** GIA' IN ESECUZIONE!", vbInformation
End
End If
End Sub
Re: check if application is already opened
Be careful, the End statement can sometimes cause problems, unloading is the safer way to go: http://www.a1vbcode.com/vbtip-148.asp