cancel
Showing results for 
Search instead for 
Did you mean: 

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

0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

cpollach
Explorer
0 Kudos

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

Answers (3)

Answers (3)

cpollach
Explorer
0 Kudos

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}

0 Kudos

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..

cpollach
Explorer
0 Kudos

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