Help with replacing a positive value with a negative depending of a value of another field?

My fields:AdjType_1 – Dialog List - Editable

Value will be the word: NEG or POS

AdjQty_1 – Number – Editable

Default value - (@If(@IsNumber(AdjQty_1);AdjQty_1;0))

I need the AdjQty_1 field to default to zero, which can be edited with a new number eg 10 (This is working fine)

What I need to do is when AdjType_1 equals NEG then the number in AdjQty_1 is converted to display a negative number eg -10.

Ihave tried the following in Input Translation:

vtemp:=(@If(@IsNumber(AdjQty_1);AdjQty_1;0));

@If(AdjType_1 =“NEG”;-vtemp;vtemp)

This formula works, BUT when the user click on another field the negative disappears leaving 10, click again and the negative comes back.

As the form will be edited by a number of users, I need the value to stay negative.

Your help is very much appreciated

Marion

Subject: QuerySave event

Another way to solve it would be to put code in QuerySave, if you don’t need the value to show up as negative until after the document is saved.Only relevant code below. Also, don’t use variable/field names like AdjType_1, etc… Just a recommendation.

Dim quantity as String

Dim negative as Boolean

'*** Get quantity and make sure it is numeric

quantity = uidoc.FieldGetText(“Quantity”)

If IsNumeric(quantity) = False Then

MsgBox “Quantity is not a number”

Continue = False

Exit Sub

End If

'*** Check if negative or positive

If uidoc.FieldGetText(“Type”)=“Neg” Then

negative = True

Else

negative = False

End If

'*** Convert to negative number if Type field is “Neg”

If negative Then

If Cint(quantity)>0 Then

Call uidoc.FieldSetText(“Quantity”, 0 - Cint(quantity))

End If

End If

Something like that. :slight_smile:

Subject: input translation being done every time

Your input translation code is fine, but only if it only runs once. What you need to do is make sure that you don’t keep running it every time the form recalculates.The simplest fix is to change the second line to check that the number is not already negative, so that it reads like this:

vtemp:=(@If(@IsNumber(AdjQty_1);AdjQty_1;0));

@If(AdjType_1 =“NEG” & vtemp>0;-vtemp;vtemp)

Hope this helps,

Phil

Subject: Works thanks for your help