cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Report formula Field Customizing

0 Kudos
320

I have a report that expects a number and dotted line to match a field called qty_required.

I created a formula field but the qty_required number can be up to 100 and I didn't want to write 100 if statements.

This is what I currently have:

if {Command.QTY_REQUIRED} = 1

then

'1. _ _ _ _ _ '

else

if {Command.QTY_REQUIRED} = 2

then

'1. _ _ _ _ _ 2. _ _ _ _ _'

else

if {Command.QTY_REQUIRED} = 3

then

'1. _ _ _ _ _ 2. _ _ _ _ _ 3. _ _ _ _ _'

else

if {Command.QTY_REQUIRED} = 4

then

'1. _ _ _ _ _ 2. _ _ _ _ _ 3. _ _ _ _ _ 4. _ _ _ _ _'

else

if {Command.QTY_REQUIRED} = 5

then

'1. _ _ _ _ _ 2. _ _ _ _ _ 3. _ _ _ _ _ 4. _ _ _ _ _ 5. _ _ _ _ _'

else

if {Command.QTY_REQUIRED} = 6

then

'1. _ _ _ _ _ 2. _ _ _ _ _ 3. _ _ _ _ _ 4. _ _ _ _ _ 5. _ _ _ _ _ 6. _ _ _ _ _'

Can you help me with getting the formula to populate in this format?

View Entire Topic
DellSC
Active Contributor
0 Kudos

You could try something like this:

Local StringVar result := "";
Local NumberVar i;
For i := 1 to {Command.QTY_REQUIRED} Do
(
  result := result + ToText({Command.QTY_REQUIRED}, 0, '') + '._ _ _ _ _';
)
result

This look will walk through from 1 to the number in the quantity and build the string.

-Dell

0 Kudos

When I tried this I get an error that the last line error 'the remaining text does not appear to be part of the formula. I have the result in the parathesis and get a True result.

DellSC
Active Contributor

Oops! I forgot to add the semi-colon after the closing parenthesis. Try this:

Local StringVar result := "";
Local NumberVar i;
For i := 1 to {Command.QTY_REQUIRED} Do
(
  result := result + ToText({Command.QTY_REQUIRED}, 0, '') + '._ _ _ _ _';
);
result

-Dell

0 Kudos

This worked perfect!!!! thanks so much for your help.