1. Tracy Lamb
  2. PowerBuilder
  3. Monday, 15 July 2024 19:44 PM UTC

Hi all,

I'm trying to add a STOP button on the screen for a merge process so the user can stop the loop if the number of certificates on the selected salesorder is high. I added a yield() statement to the loop and a check for the value of the instance variable ib_stop, but it loops through so fast that often times the STOP click is missed.  Sometimes if I double-click the STOP button, it works, but not always.  Here's the code:

//wf_merge_each
integer li_CertCount, li_ThisCert, li_x, li_rc

//Loop through all of the Certs in the ddlb
ib_stop = FALSE
cb_stop.visible = TRUE
li_CertCount = ddlb_certs.TotalItems()
for li_x = 1 to li_CertCount
	st_6.Text = "Merging " + string(li_x) + " of " +  string(li_CertCount) + " ... Please wait..."
	ddlb_certs.SelectItem(li_x)
	ddlb_certs.Event SelectionChanged(li_x)
	li_rc = wf_merge_one()
	if li_rc = -1 then
		return
	end if
	Yield()
	if ib_stop = TRUE then
		exit
	end if
next
if ib_stop = TRUE then
	st_6.Text = "Merged " + string(li_x) + " of " +  string(li_CertCount) + " ... Merge cancelled..."
else
	st_6.text = "Merge complete: " + string(li_CertCount) +" documents."
end if

cb_stop.visible = 	FALSE
return

Any thoughts?  I tried adding 4 more Yields() but that doesn't fix the problem.

TIA,
Tracy

 

Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 16 July 2024 13:18 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi,

Please find attached my little test case (powerbuilder 2019 R3)

 The code is in w_yield_sleep_main:

- external function declaration 

- instance variable ib_cancel

- and the code in the buttons

Attachments (1)
Comment
  1. Tracy Lamb
  2. Tuesday, 16 July 2024 20:52 PM UTC
This is a definite improvement, but sometimes I still have to click the STOP button twice. So I just changed the text on the button to "Click twice to Stop", lol. I'm using a 500ms sleep. 250ms was too fast, and I had to click STOP 3 or 4 times. I also added a Yield() statement before each dw retrieve in the ddlb.selectionchanged event. The selectionchanged event retrieves data into 3 different dws. My data is on a remote server, so I'll be curious to see how well this works for my customer when he's connected locally to his server.

Thanks Miguel!

~~~Tracy

  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 16 July 2024 06:47 AM UTC
  2. PowerBuilder
  3. # 1

Hi,

Try inserting a delay by for example using Sleep(1), just for testing.

Now that's a big delay, it would be better to use a WinAPI. (later I'll post its declaration).

Comment
  1. Tracy Lamb
  2. Tuesday, 16 July 2024 12:47 PM UTC
Would Sleep() work? Help says it suspends the application... I just want the loop to pause long enough to allow the user to click the STOP button.
  1. Helpful
  1. Miguel Leeuwe
  2. Tuesday, 16 July 2024 13:01 PM UTC
Powerbuilder's Sleep function should work, but can only be specified in full seconds. I'm looking at some code that I have to use the WinApi Sleep which can be specified in milliseconds.

I'll try to make a simple test app. Give me some time please.

regards
  1. Helpful
  1. Miguel Leeuwe
  2. Tuesday, 16 July 2024 13:15 PM UTC
This is the External function declaration:

Subroutine Sleep_ms( ULONG ulMilliseconds ) Library "Kernel32.dll" alias for "Sleep"



After your Yield(), call Sleep_ms(1)

1 millisecond was enough for my test case (which I'll now attach in another answer).
  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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.