By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,642 Members | 2,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,642 IT Pros & Developers. It's quick & easy.

how to make the exe file be a single application on running mode

xxoulmate
P: 77
how to make the exe file made in vb to be run only once..,
i mean is only one application can be run a time.

commonly we can run multi application of a specific exe file..
ex. test.exe
can be run as many as we can....
how can it be set that exe to be not run so many, and i wanted is just one only.
how can it be done..
tnx more power.....
Dec 18 '07 #1
Share this Question
Share on Google+
10 Replies


lotus18
100+
P: 866
how to make the exe file made in vb to be run only once..,
i mean is only one application can be run a time.

commonly we can run multi application of a specific exe file..
ex. test.exe
can be run as many as we can....
how can it be set that exe to be not run so many, and i wanted is just one only.
how can it be done..
tnx more power.....
Hi

If I got your question add this to your codes:

Expand|Select|Wrap|Line Numbers
  1. If App.PrevInstance = True Then
  2.         MsgBox "Cannot run the program. Program is already running.", 64
  3.         End
  4. End If
'This will check if your application is already running.

Note: Add this codes at the start of your program (Sub Main). Be sure your Startup object is your Sub Main.

Expand|Select|Wrap|Line Numbers
  1. Public Sub Main()
  2. <Add it here>
  3. <Your first form to be showed>
  4. ...
  5. End Sub
  6.  

Rey Sean
Dec 18 '07 #2

vdraceil
100+
P: 236
Hi

If I got your question add this to your codes:

Expand|Select|Wrap|Line Numbers
  1. If App.PrevInstance = True Then
  2.         MsgBox "Cannot run the program. Program is already running.", 64
  3.         End
  4. End If
'This will check if your application is already running.

Note: Add this codes at the start of your program (Sub Main). Be sure your Startup object is your Sub Main.

Expand|Select|Wrap|Line Numbers
  1. Public Sub Main()
  2. <Add it here>
  3. <Your first form to be showed>
  4. ...
  5. End Sub
  6.  

Rey Sean
Is it necessary to add that code in main()? I think it would run even if it is added to form's load event...
Till now i've never used main(). Pls can u give me the place where main() must be strictly used..
Jan 3 '08 #3

lotus18
100+
P: 866
Is it necessary to add that code in main()? I think it would run even if it is added to form's load event...
Yes you are right, it is not necessary to add that code in Sub Main(). Perhaps you can add that in a splash form (if you have).
Till now i've never used main(). Pls can u give me the place where main() must be strictly used..
What do you mean by this?

Rey Sean
Jan 3 '08 #4

Expert 5K+
P: 8,434
What do you mean by this?
vdraceil must be using a startup form, rather than Sub Main.

One thing to note. I'm pretty sure I have encountered an error when I used the End statement in Sub Main. If this happens, just change the End to Exit Sub. As long as you haven't loaded any forms yet, this should work OK.
Jan 4 '08 #5

lotus18
100+
P: 866
vdraceil must be using a startup form, rather than Sub Main.
Maybe vdraceil didn't understand my post (2nd). OK, it's my fault, insufficient explanation : )

Rey Sean
Jan 4 '08 #6

vdraceil
100+
P: 236
Maybe vdraceil didn't understand my post (2nd). OK, it's my fault, insufficient explanation : )

Rey Sean
U were clear with the use of PrevInstance property..as killer said i always use a startup form..i just wanted to know why programmers use sub main()? Is there any advantage in using it?
Jan 4 '08 #7

Expert 5K+
P: 8,434
U were clear with the use of PrevInstance property..as killer said i always use a startup form..i just wanted to know why programmers use sub main()? Is there any advantage in using it?
To be honest, I think it's largely a matter of personal preference.

On the other hand, a form is really just a user interface element (similar in many ways to a text box or scroll bar). So in some ways it seems more logical to start the actual program and have it display whatever forms are appropriate, rather than starting up a form and then having other things happen. I mean, you wouldn't expect to run a text box and have it create a form to hold it, and so on.

Besides, there may be cases where your application doesn't include a form at all. For instance, I sometimes write a "quick and dirty" program to read a text file, make some change, and write out a new one. For something that only I will run, and which will take maybe five seconds, a user interface is just a waste of time. It's simpler to just write the routine to do the work, and run it.
Jan 4 '08 #8

xxoulmate
P: 77
thnx for post.,
ill try the code.,
Jan 17 '08 #9

Expert 5K+
P: 8,434
Let us know how it turns out.
Jan 17 '08 #10

xxoulmate
P: 77
many thanks.,
it runs as i wish......
Jan 19 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.