Skip to main content

Search

Search

Script divide number into equals

Comments

4 comments

  • Avatar
    Peter Thane

    There is probably a better way to achieve the number of labels to print but the code below works. You need to make the Copies field a VB Script>Event Controlled Script and edit the OnIdenticalCopies to include the code below.

    I called my field, that has the total number in it, "TheNumber" so I could reference it in the VB.

    Value = Format.NamedSubStrings("TheNumber").Value

    Value1 = Value/100

    Value2 = Right(Value,2)

    If Value2 > 0 then 

    Value2 = 1

    else Value2 = 0

    end if

    Value1 = Int(Value1)

    Value = Value1 + Value2 

     

    1
  • Avatar
    Jose R

    Thanks for the input, Peter!

    I still couldn't divide the amount into the 4 labels. 350 = 100 + 100 + 100 + 50. My code returns 53 in all of them.

    I created a regular text object called nResult and I place my code the "OnSerialize" event in the Event List, is it correct or is there some other way?

    Thanks in advance!

    0
  • Avatar
    Peter Thane

    Sorry I thought you were just after printing the correct number of labels. For the fields:

    1. Add a sequential number field that resets every print job and give this field a name (I used "CounterUp"). This field can be dragged off the side of the label so it is not in the printable area.
    2. On the File Print Screen amend the Number of Identical Copies to use the Print Dialog option 
    3. For the Serial Numbers add the VB script used above into this field instead but make set it to run OnSerialise and not OnIndenticalCopies. Name this Data Source too, I called this LblQty
    4. Next amend your 100/50 field and make this a VBScript > EventControlled > OnIdenticalCopies field and add the VB below into this. 

    Value = Format.NamedSubStrings("LblQty").Value

    Value1 = Format.NamedSubStrings("CounterUp").Value

    Value2 = Format.NamedSubStrings("TheNumber").Value


    If Value = 1 then

    Value = 100

    elseif Value = Value1 then

    Value = Right(Value2,2)

    else Value = 100

    end if

    Value = Value

    This should then give you something like this:

     

    1
  • Avatar
    Jose R

    Good morning, Peter!

    Thanks a lot for the help. That's perfect. Just what I needed.

     

    0

Please sign in to leave a comment.