Skip to Content
0

Failed to add trailing 0s to field during SetItem() in itemchanged event

Mar 05 at 12:31 PM

46

avatar image
Former Member

Hello. Please help me on this problem which I have tried to fix for hours but failed.

I am doing a SetItem() on a field in itemchanged() event. The requirement is the field will always be 6 numeric characters. So if users types 11, on tab-out I am trying to set 0000 so the value becomes 110000.

During debug, I see the value 110000 being set in datawindow but when the execution goes to itemfocuschanged() event, the value automatically changes to 11.

Initially I thought the field is Char type so that may be a issue but its not. The behavior is same for Long type field also. I have also tried putting AcceptText() in the itemChanged() and ItemFocusChanged() Event but no sucess.

Below is my code in Itemchanged event():

ls_col_value = This.GetItemString(row,"col_name")//not mentioning actual column name due to security reasons//

IF Len(data) < 6 THEN

data = data + fill("0", 6 - Len(data))

This.SetItem(row, "col_name", data)

END IF

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Chris Pollach Mar 05 at 02:21 PM
0

Hi Ashish;

If you have and Display or Edit masks in effect, they could suppress the trailing zeros. The value may very well be 11000. Also, check the DW column definition as well to make sure that it can handle the extra length.

Regards ... Chris

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 05 at 05:16 PM
0

Hi Chris,

Thanks for replying. The field is a regular column with no mask. The field length is 10 so it should no be an issue.

I will create a new workspace with similar environment to analyse it further. I will update the forum.

Thanks..

Share
10 |10000 characters needed characters left characters exceeded
Chris Pollach Mar 05 at 09:52 PM
0

Ahhh ....

1) Remove the GetItemString () unless you need the previous value.

2) The SetItem ( ) should not be used to set the value.

3) The Data argument will be moved to the DWO's primary buffer at the end of this script. So after padding out the data argument just issue ... RETURN 0 {accept the value}

Share
10 |10000 characters needed characters left characters exceeded
Chris Pollach Mar 05 at 10:15 PM
0

Try this ....

String ls_name
String ls_data

ls_name = String ( DWO.Name )

ls_data = Trim ( data )
Choose case ls_name
case "<your col name>"
IF Len ( ls_data ) < 6 then
data = ls_data + fill ( "0", 6 - Len ( ls_data ) )
END IF
end choose

Return 0

Share
10 |10000 characters needed characters left characters exceeded