Adam February 2016

remove decimal and leading zeros

Below is some vbscript that populates a field called Lot. At the moment when I run this the Lot field is displaying the ManualLot field as 123456.000000.

Does anyone know how I can change the code below to make 123456.000000 just 0000123456? So it removes the .000000 and starts with 0000 instead.

Function ManualLot_OnAfterChange()
  If Backflushing.CodeObject.Quantity < 0 Then
    Backflushing.CodeObject.Lot = Backflushing.CodeObject.ManualLot
  Else
    If Backflushing.CodeObject.Quantity > 0 Then
      Backflushing.CodeObject.Lot = 0
    End If
  End If
End Function

Answers


JNevill February 2016

You could use Split() get the value to the left of the decimal, and then use Left() to stick some zeros in front of it.

'how long the number should be
testLength=10

'The number we are changing
test="12345.00000"

'split(test, ".")(0) will get us the values to the left of the decimal
test=LEFT("000000000000",  testLength-len(split(test, ".")(0))) & split(test, ".")(0)

msgbox(test)


Adam February 2016

Backflushing.CodeObject.Lot = RTrim (Backflushing.CodeObject.ManualLot)

Fixed it for me. Thanks for the help though JNevil got me on right track.

Post Status

Asked in February 2016
Viewed 3,922 times
Voted 7
Answered 2 times

Search




Leave an answer