Substring problem

Keve G??borKeve G??bor hungary
edited 3:47AM in FastReport .NET
Hello!

In the attached example, you can see 2 textobject. The green one working fine, but the red one not.
If i change the Parameter1 Expression property to nothing from "", the red one working fine. But if the property value "", the report engine say:
Inner exception:
startIndex cannot be larger than lenght of the string
Parameter name startIndex

red Text object value:

[IIf(Length([Parameter1])>0,Substring([Parameter1],1,1),[Parameter2])]

Can you explain me, what the problem of this expression?

Thanks!

Comments

  • StarkStark Syria
    edited August 2010
    Hi , have a good day

    The Error is very clear , I will try to Explain it in details :

    1) This One "Substring([Parameter1],1,1)" is try to select a string from paramter1
    Which start with character of index 1 and end at character of index 1

    For Example :
    if paramter1 = "Stark" then SubString([paramter1], 1,1) will give the result "t"
    BUT
    if paramter1 = "" then SubString([paramter1], 1,1) will throw an error because there is no character at Index 1 , paramter1 has Zero Characters

    And in your Attachment report Parameter1 = "" , and that is why you get an error !


    Solution :

    you have two ways :
    *) Give Paramter1 some value ,
    OR
    *) replace the SubString([paramter1], 1,1) With SubString([paramter1], 0,0)



    Hope this help




    P.S :
    I didn't know what are you trying to achieve , or why paramter1 has the value "" ?
  • Keve G??borKeve G??bor hungary
    edited August 2010
    Hello Stark!

    Thanks the answer!

    You right! But...

    I think that due the IIf condition, the Substring procedure should not be evaluate, because the Parameter1 length = 0.

    The right evaluation order is:

    <!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto-->IIf -> Length(Parameter1)>0 -> false -> Parameter2
    -> true -> Substring(Parameter1,1,1)<!--fontc--></span><!--/fontc-->

    If Parameter1 value is "" then Lenght(Parameter1) = 0.

    But i think the real evaluation start within.

    So, clarifying my question:
    Why evaluate the Substring function the engine, if Parameter1.Lengt()==0?

    [img]style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> regards, Gabor Keve[/img]
    Stark wrote: »
    Hi , have a good day

    The Error is very clear , I will try to Explain it in details :

    1) This One "Substring([Parameter1],1,1)" is try to select a string from paramter1
    Which start with character of index 1 and end at character of index 1

    For Example :
    if paramter1 = "Stark" then SubString([paramter1], 1,1) will give the result "t"
    BUT
    if paramter1 = "" then SubString([paramter1], 1,1) will throw an error because there is no character at Index 1 , paramter1 has Zero Characters

    And in your Attachment report Parameter1 = "" , and that is why you get an error !


    Solution :

    you have two ways :
    *) Give Paramter1 some value ,
    OR
    *) replace the SubString([paramter1], 1,1) With SubString([paramter1], 0,0)



    Hope this help




    P.S :
    I didn't know what are you trying to achieve , or why paramter1 has the value "" ?
  • StarkStark Syria
    edited August 2010
    You are welcome !
    I think that due the IIf condition, the Substring procedure should not be evaluate, because the Parameter1 length = 0.
    I was think the same , Until I saw your Question , because C# didn't do that
    string res = string.Empty;
    string paramter1 = "";
    string paramter2 = "text";
           
    res = paramter1.Length > 0 ? paramter1.Substring(1, 1) : paramter2;
    Console.WriteLine(res);
    

    So, clarifying my question:
    Why evaluate the Substring function the engine, if Parameter1.Lengt()==0?

    I think this is how fast report works , I really don't know much about it's engine , ( I am just a user for fast-report [img]style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> ) May be one of the makers can answer you ,[/img]

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.