Programatically close application and open the other

Discussions about CSEntry
Post Reply
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Programatically close application and open the other

Post 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.
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: Programatically close application and open the other

Post 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.
copernix2
Posts: 18
Joined: November 23rd, 2014, 7:46 am

Re: Programatically close application and open the other

Post by copernix2 »

Try this code

Code: Select all

DISTRICT PROC
execPFF(".\Main.pff");
stop(1);
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Programatically close application and open the other

Post 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.
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Re: Programatically close application and open the other

Post 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?
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Programatically close application and open the other

Post 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?
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Re: Programatically close application and open the other

Post by munirmdee1 »

Yes Josh, it closes Menu application and opens Main application and closes it. I don't know why...
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
Post Reply