Strange subroutine output

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
 

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
 

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
 
Top