Monday, March 19, 2012

Line Break down

I have a forumla {@.frmPrevMonth} and it contains information like... "21,36.02,11141.75,1" which it came from a Parameter field.

It can contain more of less information.

What I need is that it can be broke down in order in which they came.

1st Detail line: 21
2nd Detail line: 36.02
3rd Detail line: 11141.75
4th Detail line: 1

How can I achive this?You are going to use the left(), Mid(), and right() functions.
You will have 4 formulas.
This will work for the number you show.

1. Left({@.frmPrevMonth} ,2) // gets 21
2. Mid({@.frmPrevMonth} ,4,5) // gets 36.02
3. Mid({@.frmPrevMonth} 10,8) // gets 11141.75
4. Right({@.frmPrevMonth} ,1) // gets 1

GJ|||I forgot to put down that the numbers vary in size and it is not always 4 things I need. It can be a total of 10 lines or 1 line.|||Ok here is a formula that will get the first strings before the first comma.
I assume you want the values between the commas.

'This formula uses Basic syntax

dim StringInput as string

dim Character as string

dim NumberOfCharacters as number

'The StringInput, Character and NumberOfCharacters

'variables can be changed to your values

StringInput = {@.Number}

Character = ","

NumberOfCharacters = 0

'NumberOfCharacters specifies that the token returned

'If the token to be retrieved comes before the first

'occurrence of Character, use 0 for NumberOfCharacters.

dim Token as number

dim Increment as number

dim Output as string

dim Ender as number

Ender = NumberOfCharacters + 1

do until Token = Ender or Increment = length(StringInput)

Increment = Increment + 1

if StringInput(Increment) = Character then Token= Token + 1

if Ender - Token = 1 and StringInput(Increment) <> Character then Output = Output + StringInput(Increment)

loop
Formula = Output

If you could have up to 10 lines then you will have 10 formulas the way I show, just change the variable at NumberOfCharacters. 1st formula has a 0, 2nd would have a 1 and up to 9 for 10 lines.

Hope that makes sense, someone else might have an easier way of doing this.

GJ|||Look at the help for the Split function, and on arrays.
e.g.
stringvar array parts := split({table.field}); //or maybe numbervar, if all your parts are numbers

parts[2] //return the 2nd part|||Oops, meant to add the 2nd parameter to the split function:
split({table.field}, ',');|||I tried the split function.

Attached is what I am looking for. Thanks.|||Ok here is a formula that will get the first strings before the first comma.
I assume you want the values between the commas.

'This formula uses Basic syntax

dim StringInput as string

dim Character as string

dim NumberOfCharacters as number

'The StringInput, Character and NumberOfCharacters

'variables can be changed to your values

StringInput = {@.Number}

Character = ","

NumberOfCharacters = 0

'NumberOfCharacters specifies that the token returned

'If the token to be retrieved comes before the first

'occurrence of Character, use 0 for NumberOfCharacters.

dim Token as number

dim Increment as number

dim Output as string

dim Ender as number

Ender = NumberOfCharacters + 1

do until Token = Ender or Increment = length(StringInput)

Increment = Increment + 1

if StringInput(Increment) = Character then Token= Token + 1

if Ender - Token = 1 and StringInput(Increment) <> Character then Output = Output + StringInput(Increment)

loop
Formula = Output

If you could have up to 10 lines then you will have 10 formulas the way I show, just change the variable at NumberOfCharacters. 1st formula has a 0, 2nd would have a 1 and up to 9 for 10 lines.

Hope that makes sense, someone else might have an easier way of doing this.

GJ

ok. how can I dynamically increase the "NumberOfCharacters" after everytime a record is read and then have it display it on the detail line?|||Have not had time today to work formula. Why not use the split function like JaganEllis suggested. It's quicker and easier to understand.

GJ|||An example to produce what I think you want:

local stringvar a := "21,36.02,11141.75,1";
local stringvar array parts := split(a, ',');
local numbervar i;
local stringvar out;

for i := 1 to ubound(parts) do
(
out := out + parts[i] + chr(13) + chr(10);
);
out

And remember to check the 'Can Grow' option for the field, in the Common tab of the Format Field option.

No comments:

Post a Comment