Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Carloid De Guzman
  Where is Carloid De Guzman?
 CaloocanCity
 Philippines
 Carloid De Guzman
 To: Chester Costa
  Where is Chester Costa?
 Metro Manila
 Philippines
 Chester Costa
 Tags
Subject: RE: run app once
Thread ID: 365089 Message ID: 365417 # Views: 49 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Wednesday, December 26, 2012 8:22:36 AM         
   


I think chester costa wants to run his application in one instance.

Try this:

This code should be placed in your MAIN.PRG.
* The key is the table req_id.sys being created
* as soon as the program starts then USE it EXCLUSIVEly.
* req_id.sys (the table) could be any name you desire.

***** Check single instance of app, my way *****
* See if table already exist
IF FILE(ADDBS(SYS(2023)) + "req_id.sys")
        * If table is already there, it was probably created by the previous instance of the app
        * but there might have been a crash or something that the app failed to delete it prior 
        * to a garceful exit
	TRY 
                * TRY to USE it EXCLUSIVEly so that succeeding program loads will not succeed in USEing it
		USE (ADDBS(SYS(2023)) + "req_id.sys") EXCLUSIVE IN 0
	CATCH TO oUseErr
                * Check error number 1705 (aka "File access denied" error) which means
                * another instance is already USEing the table
		IF oUseErr.ERRORNO = 1705
			MESSAGEBOX("Another instance of this application is already running.", ;
				64, "System message")
                        * Do whatever you need to do here then...
			QUIT
		ENDIF
	ENDTRY
ELSE
        * If table does not exist, create it with a different extension having only one field
        * This automatically opens it in EXCLUSIVE mode
	CREATE TABLE (ADDBS(SYS(2023)) + "req_id.sys") ;
		(prog_id C(10))
        * Just put any value in prog_id, it really doesn't matter
	INSERT INTO req_id (prog_id) VALUES (SYS(2015))
ENDIF
************************************************ 

DO FORM <yourloginform>


Put these in your Close/Exit Buttons.
USE IN req_id
ERASE (ADDBS(SYS(2023)) + "req_id.sys") 


Hope it helps!:)

ENTIRE THREAD

run app once Posted by Jem Carlo Mallari @ 12/21/2012 8:38:51 AM
RE: run app once Posted by Jun Tangunan @ 12/21/2012 8:47:11 AM
RE: run app once Posted by Jem Carlo Mallari @ 12/21/2012 9:06:51 AM
RE: run app once Posted by Glen Villar @ 12/21/2012 1:58:40 PM
RE: run app once Posted by Cetin Basoz @ 12/21/2012 2:54:19 PM
RE: run app once Posted by Rick Hodgin @ 12/21/2012 4:41:09 PM
RE: run app once Posted by David Mustakim @ 12/21/2012 4:59:28 PM
RE: run app once Posted by David Mustakim @ 12/21/2012 4:10:24 PM
RE: run app once Posted by Tom Saddul @ 12/21/2012 4:22:10 PM
RE: run app once Posted by Carloid Costa @ 12/26/2012 8:22:36 AM
RE: run app once Posted by Glen Villar @ 12/26/2012 1:35:49 PM
RE: run app once Posted by Jun Tangunan @ 12/27/2012 5:21:14 AM
RE: run app once Posted by Tom Saddul @ 12/28/2012 10:15:49 AM