1. John Vanleeuwe
  2. PowerBuilder
  3. Saturday, 17 December 2022 08:58 AM UTC

Hi guys,

 

Using PB2019 R3

Looking for some general advice , tips & tricks.

 

Our users are heavily using copy/paste function from windows. I have 2 little questions about this 

 

1) many times our users are copying data which isn't in the correct format. Think about a space in an amount which is copied into a decimal datawindow field. 

Do you guys use any "clean" function before the pasting of the information to prevent datawindow popups like "item does not pass validation test" ? What's the best way to handle this please ? 

 

2) Also , when this error pops up : item does not pass validation test , it takes our users 50 to a 100 times to get this window closed.  How can i gracefully let them know 1 time please ? 

 

 

 

TIA

John

 

mike S Accepted Answer Pending Moderation
  1. Monday, 19 December 2022 19:30 PM UTC
  2. PowerBuilder
  3. # 1

i have a 'paste' object and send the pasting string and reference to the datawindow instead of using just the standard PB or windows paste function.

 

first step is to change the paste string into an array of strings to handle multi column/row pastes

From there strip out spaces, remove tabs, remove CR/LF (for multi row paste) and handle moving/adding rows if it is a multi row paste. (note, if there is ONLY a space as the pasted value, it is likely they want a space so you may want to keep it rather than replace with empty string)

use the send function to send a tab to the datawindow to move to the next column

Use setcolumn and settext and accepttext to allow the datawindow logic to run for itemchanged events.

 

 

Comment
  1. John Vanleeuwe
  2. Tuesday, 20 December 2022 10:38 AM UTC
Hi Mike,



thanks for the answer , in which dw event did you code this function please ?





TIA

John

  1. Helpful
  1. mike S
  2. Tuesday, 20 December 2022 15:43 PM UTC
create a paste menu item with the ctrl-V etc to override the standard system paste event

  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Saturday, 17 December 2022 18:28 PM UTC
  2. PowerBuilder
  3. # 2

I concur: Handle any error in the ItemError event.

However, some basic pre-validation would not be out of place. For example. if the field requires a decimal value you could check the pasted data to ensure that it is NUMERIC and contains no spaces after a TRIM(<value>) is performed.


Meanwhile, a very quick and TEMPORARY work around is:

1. create an instance variable:    BOOLEAN  ib_error_already_displayed

2. in the ItemError event:

IF (NOT ib_error_already_displayed) THEN

    // display the error message

    ib_error_already_displayed = TRUE

END IF

3. In the ItemFocusChanged event and in the pfc_save event (if you are using it) clear the flag:  ib_error_already_displayed = FALSE.
    Your particular case might require the flag be cleared in another event or two; it depends on the window & the DW.


That will stop the annoying 50 instances of the error msg in its tracks.

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Saturday, 17 December 2022 14:49 PM UTC
  2. PowerBuilder
  3. # 3

Hi John;

  Does your App's DW Control try to handle / help the App user out of this predicament with PowerScript code in the ItemError event?

Regards ... Chris 

Comment
  1. John Vanleeuwe
  2. Saturday, 17 December 2022 14:55 PM UTC
Hi Chris,



nope it doesn't for the moment, but i do realise i need to come up with a solution for this.



i can go either of possible 2 ways here



option 1 : prevent that the itemerror event is triggered by cleaning the pasted data

option 2 : or handle it in the error event to a more gracefully "exit" than 50 times pressing OK



that was kinda my question , how are you guys dealing with this behaviour ?



Thanks.



Regards

John

  1. Helpful
  1. Chris Pollach @Appeon
  2. Saturday, 17 December 2022 15:21 PM UTC
Hi John;

Unfortunately, the paste operation places the data in text format into the DataWindow's keyboard input area. This is the same area that an App user would key into using their keyboard. In an ItemFocus changed, enter or an AcceptText() command is issued, the DWO then tries to validate the text input as it tries to move it to the DWO's primary buffer. If the validation sequence at that point fails, then the ItemError event is fired. That's where I normally handle the issue.

You can also handle it in the Error event but the DWO could easily fire the ItemError event multiple times. Hence, the App user having the hard time getting out of the validation sequence - which depending on your DC's code, could happen multiple times.

So just my $0.02, I would try & handle the issue in the ItemError event. The other way that I've used is to remove the validations from the DWO altogether & then validate the DWO changes under script control before issuing the Update() command.

HTH

Regards ... Chris
  1. Helpful 2
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.