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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxoulmate
    New Member
    • May 2007
    • 77

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

    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.....
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Originally posted by xxoulmate
    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:

    [CODE=vb]If App.PrevInstanc e = True Then
    MsgBox "Cannot run the program. Program is already running.", 64
    End
    End If[/CODE]

    '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.

    [CODE=vb]Public Sub Main()
    <Add it here>
    <Your first form to be showed>
    ...
    End Sub
    [/CODE]


    Rey Sean
    Last edited by lotus18; Dec 18 '07, 04:28 AM. Reason: () added

    Comment

    • vdraceil
      New Member
      • Jul 2007
      • 236

      #3
      Originally posted by lotus18
      Hi

      If I got your question add this to your codes:

      [CODE=vb]If App.PrevInstanc e = True Then
      MsgBox "Cannot run the program. Program is already running.", 64
      End
      End If[/CODE]

      '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.

      [CODE=vb]Public Sub Main()
      <Add it here>
      <Your first form to be showed>
      ...
      End Sub
      [/CODE]


      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..

      Comment

      • lotus18
        Contributor
        • Nov 2007
        • 865

        #4
        Originally posted by vdraceil
        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).
        Originally posted by vdraceil
        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
        Last edited by lotus18; Jan 3 '08, 01:24 PM. Reason: quote

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by lotus18
          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.

          Comment

          • lotus18
            Contributor
            • Nov 2007
            • 865

            #6
            Originally posted by Killer42
            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

            Comment

            • vdraceil
              New Member
              • Jul 2007
              • 236

              #7
              Originally posted by lotus18
              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?

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by vdraceil
                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.
                Last edited by Killer42; Jan 17 '08, 05:13 AM. Reason: Left out a word

                Comment

                • xxoulmate
                  New Member
                  • May 2007
                  • 77

                  #9
                  thnx for post.,
                  ill try the code.,

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Let us know how it turns out.

                    Comment

                    • xxoulmate
                      New Member
                      • May 2007
                      • 77

                      #11
                      many thanks.,
                      it runs as i wish......

                      Comment

                      Working...