1. Tracy Lamb
  2. PowerBuilder
  3. Thursday, 18 August 2022 16:50 PM UTC

Hi all,

I need to loop through a few records and if all conditions are met, run a program.  This works fine for one record.  The program I'm running requires user interaction.  Is there a way to wait for the other program to close before moving to the next record?  The other program is a C# program that prints a label.  The user has to click Print to actually print the label, in case they want to change the print template or printer.  So it could take 10 seconds, or 2 minutes.  

My loop is working fine, but it launches the label program, then moves on to the next record. And launches the label program again.  So I end up with 4 or 5 (possibly more) instances of the label program running.  I put a 10 second delay in, which gives time for the program to launch and the user to click Print.  But not much more time for anything else.

		for li_x = 1 to li_SelectedCount 
			ll_WorkOrder = this.GetItemNumber(ll_SelectedRows[li_x], "workorder")
			ls_finished = this.GetItemString(ll_SelectedRows[li_x], "certificate_done")
			if IsNull(ls_finished) then
				MessageBox("Print Label","Certificate is not started for WO# " + string(ll_WorkOrder))
			elseif ls_finished = 'F' then
				MessageBox("Print Label","Certificate not finished for WO# " + string(ll_WorkOrder))
			else
				Run(ls_file + " "  + string(ll_WorkOrder))
				//Add a pause
				StartTime = Now()
				DO
				LOOP Until SecondsAfter(StartTime,Now()) > 10
			end if
		next

 

Thanks,

~~~Tracy

Accepted Answer
Tracy Lamb Accepted Answer Pending Moderation
  1. Thursday, 18 August 2022 18:39 PM UTC
  2. PowerBuilder
  3. # Permalink

Thank you Chris and especially Roland for the solution!

I added the n_runandwait object to my project from the Roland's code, and changed my code as follows:

		n_runandwait lnv_RunAndWait
		for li_x = 1 to li_SelectedCount 
			ll_WorkOrder = this.GetItemNumber(ll_SelectedRows[li_x], "workorder")
			ls_finished = this.GetItemString(ll_SelectedRows[li_x], "certificate_done")
			if IsNull(ls_finished) then
				MessageBox("Print Label","Certificate is not started for WO# " + string(ll_WorkOrder))
			elseif ls_finished = 'F' then
				MessageBox("Print Label","Certificate not finished for WO# " + string(ll_WorkOrder))
			else
				ls_file = "C:\Cal Labels\CalLabels.exe " + string(ll_WorkOrder)
				lnv_RunAndWait.RunAndWait(ls_file, 1)
			end if
		next

Works like a charm! I even waited 5 minutes between prints just to make sure!

~~~Tracy

 

 

Comment
  1. Chris Pollach @Appeon
  2. Thursday, 18 August 2022 18:45 PM UTC
That's awesome news Tracy .. thanks for the feedback! :-)
  1. Helpful
  1. Tracy Lamb
  2. Tuesday, 23 August 2022 22:05 PM UTC
So, today I "found" an opportunity to use Roland's ShellRun() function in the n_runandwait object. Awesome!

Thanks again Roland!
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 18 August 2022 17:09 PM UTC
  2. PowerBuilder
  3. # 1

Hi Tracy;

  Instead, replace the PB Run() command with Roland's "Run & Wait" logic, as follows:

https://www.topwizprogramming.com/freecode_runandwait.html

Regards ... Chris 

Comment
  1. Chris Pollach @Appeon
  2. Thursday, 18 August 2022 17:31 PM UTC
AFAIK, it should migrate OK to PB2021 - just use the PB 12.6 code base version to migrate.
  1. Helpful 1
  1. John Fauss
  2. Thursday, 18 August 2022 17:38 PM UTC
Roland's excellent example uses Windows API functions such as ShellExecute and ShellExecuteEx, so it will work fine. Download and open the PB 12.6 version, as Chris said.
  1. Helpful 1
  1. Tracy Lamb
  2. Thursday, 18 August 2022 17:40 PM UTC
Never mind... migrated and opens fine.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.