Page 1 of 1
Programatically close application and open the other
Posted: March 30th, 2016, 7:57 am
by munirmdee1
Hi everyone
I have two application here, one I use as a Menu and the other one I use as the Main apllication.
When I run Menu application it gives me options as either to Add New Data, Edit Existing Data or Quit the Application. So I need after I choose option like Add New Data or Edit Existing Data the Menu apllication should close, and Main application should run.
In Menu application there are two questions, CITY and DISTRICT, options appear after I enter DISTRICT, so I need after I enter the DISTRICT the Menu application should close, and Main application shoud run.
This is what I did in the Postproc of DISTRICT:
DISTRICT PROC
execPFF(".\Main.pff");
execPFF(".\Menu.pff",stop);
That means, it runs the Main Application and close the Menu Application, but unfortunately it doesn't close Menu Application and it does not Open or Run Main Application.
I need your support guys, whats wrong with that?, why it doesn't work?, is there other way to do that?
Thanks in advanced.
Re: Programatically close application and open the other
Posted: March 30th, 2016, 10:41 am
by Saint
Hi, I hope you have previously launched the Main application (.pen or .enc) to create the .pff. If the .pff does not exist yet, it will not run. If the .pff does exist, the opening of Main and the closing of the Menu should be in the same line of code as follows.
Code: Select all
execPFF(".\Main.pff", minimized, wait)
Best.
Re: Programatically close application and open the other
Posted: March 30th, 2016, 11:26 am
by copernix2
Try this code
Code: Select all
DISTRICT PROC
execPFF(".\Main.pff");
stop(1);
Re: Programatically close application and open the other
Posted: March 30th, 2016, 7:30 pm
by josh
The way to do this depends if you are on Windows or Android.
On Windows you can have two data entry applications running at once so rather than stopping the menu program you can have it wait while the main app runs. This is the approach that @Saint recommended:
if execPFF(".\Main.pff", minimized, wait) <> 1 then
errmsg("Failed to launch main application");
endif;
Note that it is a good idea to check the return value of execpff because it can fail in certain cases.
If you are on Android, it is not possible to run two CSPro applications at the same time so you need to use the stop parameter in execpff when launching the main app. Adding the stop parameter causes the menu application to end as soon it is able to launch the main application. It is better to do this in a single command rather than an execpff followed by a stop.
if execPFF(".\Main.pff", stop) <> 1 then
errmsg("Failed to launch main application");
endif;
Note that using the stop parameter will work on both Android and Windows but using wait will only work on Windows. Of course, if you use stop then you need to make your main program relaunch the menu program when it exists using the same approach.
In your case, it seems that execpff is failing. This is probably because the path to the file Main.pff is not correct. When you use the path "./Main.pff" CSPro looks in the same folder as your menu application. If you have it in a different folder you may need to use something like "../Main/Main.pff" instead. If the path is not the problem then there could be a syntax error in Main.pff.
Re: Programatically close application and open the other
Posted: April 1st, 2016, 4:00 am
by munirmdee1
Hi Josh,
Actually I've used the same code for android you posted above:
if execPFF(".\Main.pff", stop) <> 1 then
errmsg("Failed to launch main application");
endif;
What is happening is, it opens/runs the main.pff and then it closes in andriod, but in windows it works fine, in window it closes Menu Application and runs Main Application. The problem when it comes to Android, it closes Menu Application and it runs Main Application and it closes it. I dont know why huh!!..
Any reasons for that or suggestions?
Re: Programatically close application and open the other
Posted: April 1st, 2016, 10:40 am
by josh
I'm not sure what you mean. Are you saying that on Android is closes the main application immediately without letting you enter any data?
Re: Programatically close application and open the other
Posted: April 1st, 2016, 8:21 pm
by munirmdee1
Yes Josh, it closes Menu application and opens Main application and closes it. I don't know why...