Home Ask Login Register

Developers Planet

Your answer is one click away!

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
    If Backflushing.CodeObject.Quantity > 0 Then
      Backflushing.CodeObject.Lot = 0
    End If
  End If
End Function


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

'The number we are changing

'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)


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


Leave an answer

Quote of the day: live life