CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Line Break down

  1. #1
    Join Date
    Jan 2003
    Location
    St Paul, MN - USA
    Posts
    48

    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?

  2. #2
    Join Date
    Sep 2005
    Location
    Colorado, USA
    Posts
    86

    Re: Line Break down

    You are going to use the left(), Mid(), and right() functions.
    You will have 4 formulas.
    This will work for the number you show.
    Code:
    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

  3. #3
    Join Date
    Jan 2003
    Location
    St Paul, MN - USA
    Posts
    48

    Re: Line Break down

    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.

  4. #4
    Join Date
    Sep 2005
    Location
    Colorado, USA
    Posts
    86

    Re: Line Break down

    Ok here is a formula that will get the first strings before the first comma.
    I assume you want the values between the commas.
    Code:
    '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

  5. #5
    Join Date
    May 2006
    Posts
    324

    Re: Line Break down

    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

  6. #6
    Join Date
    May 2006
    Posts
    324

    Re: Line Break down

    Oops, meant to add the 2nd parameter to the split function:
    split({table.field}, ',');

  7. #7
    Join Date
    Jan 2003
    Location
    St Paul, MN - USA
    Posts
    48

    Re: Line Break down

    I tried the split function.

    Attached is what I am looking for. Thanks.
    Attached Images Attached Images  
    Last edited by vbjohn; March 29th, 2007 at 09:18 AM.

  8. #8
    Join Date
    Jan 2003
    Location
    St Paul, MN - USA
    Posts
    48

    Re: Line Break down

    Quote Originally Posted by gjack72
    Ok here is a formula that will get the first strings before the first comma.
    I assume you want the values between the commas.
    Code:
    '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?

  9. #9
    Join Date
    Sep 2005
    Location
    Colorado, USA
    Posts
    86

    Re: Line Break down

    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

  10. #10
    Join Date
    May 2006
    Posts
    324

    Re: Line Break down

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured