Strange subroutine output

Discussion in 'Bug Reports' started by petrbury, Jan 31, 2008.

  1. petrbury

    petrbury Member Licensed User

    Hi,
    sometimes I need to fill in a string with a character to achieve a concrete length of this string. So I've written a simple subroutine, which is working for me for a quite long time. Now I found a problem when I use optimized compilation. You can see it on attached example.

    Try to write for example number 1 to Input textbox and click on OK button. On the Result textbox should appear 00001 (subroutine fills it in 5 character length).
    From IDE and from non optimized compilation it works. But if I use optimized compilation in the Result textbox is 001. Strange.

    Has anybody some idea, please ?
    Petr
     
  2. agraham

    agraham Expert Licensed User

    It's because you have StrLength(inp) in your For condition. In the IDE it is calculated once at the start of the loop, in the compiler it is calculated each pass round the loop. This works

    i = length - StrLength(inp)
    For sdi = 1 To i
     
  3. petrbury

    petrbury Member Licensed User

    You're very fast and you're right.
    I didn't know about this. It means I must check all my old programs for it.
    Thank you very much Agraham.
    Petr
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    This will be fixed in the next release.
     
Loading...