Page 1 of 1

Wrong result on format($i, " 0")

Posted: 09 Jan 2012 23:39
by PeterH
I hope this really is a bug?
(This is not explicitly described, but just assumed by me. So it also could be a wish...)

Info: in the following text " 0" always is meant to contain 2 blancs in front of the "0"!!!
(Don't want to write all text in a code-box...)

format($i, "000") formats $i as 3 bytes with leading zeros.
I think format($i, " 0") should format to 3 characters with leading " "? But it just prefixes $i with double " ".

For demonstration a little script - just paste it to "Try Script".
It shows 2 chapters with " 0", but bad formatting,
and a 3rd chapter with "000", well formatted, but with leading zeros.
All 3 looking bad, I think.

Code: Select all

   $t = "";
   $i = 7;
   While ($i < 11) { $i++;
      $t = "$t<crlf>".Format($i, "  0")." => Some text...";
   }
   $t = "$t<crlf>...";
   $i = 97;
   While ($i < 101) { $i++;
      $t = "$t<crlf>".Format($i, "  0")." => Some text...";
   }
   $t = "$t<crlf>...";
   $i = 7;
   While ($i < 11) { $i++;
      $t = "$t<crlf>".Format($i, "000")." => Some text...";
   }
   $t = "$t<crlf>...";
   $i = 7;
   While ($i < 11) { $i++;
      $t = "$t<crlf>".Substr("  $i", -3)." => Some text...";
   }
   Text $t;
OK - just the idea: I could help myself out with Substr(" $i", -3) but I think the format($i, " 0") would be more descriptive? (I just added this as the 4th chapter in above script.) This is the result I want...

By the way, is there a way to stop a looping script, e.g. such a While-loop as above, with forgotten $i++? ESC didn't help, I had to close XY...
(And it seems I love to forget such things :? )

Re: Wrong result on format($i, " 0")

Posted: 09 Jan 2012 23:44
by highend
By the way, is there a way to stop a looping script, e.g. such a While-loop as above, with forgotten $i++? ESC didn't help, I had to close XY...
Endless loop, no way to stop the application that invokes this. Bad programming behavior *g* (<- happened to me as well)

Just take an editor that allows you to replace inserted text with a template automatically?

E.g. EditPlus (http://www.editplus.com) or many others of that kind.

And as a nice addition (it allows you to use your favorite text editor to insert code into the "Try script" window of XYplorer): http://www.donationcoder.com/forum/inde ... ic=27479.0

Re: Wrong result on format($i, " 0")

Posted: 10 Jan 2012 09:00
by admin
To output a number with leading spaces you can use @ as placeholder:

Code: Select all

text format($i, "@@@");
It's a bit scarcely documented by MS but it seems to work.

Re: Wrong result on format($i, " 0")

Posted: 10 Jan 2012 10:23
by PeterH
You are right: format($i, "@@@") returns what I want! Thanks!

Maybe you should add it as second example to the documentation of format function? (Direct behind "000".)
So if I name it "bug" it's a "lack-of-documentation bug" :wink:

If you use an MS-function, and they do provide some documentation, could you add a reference, too?
I just tried Google - but fount only other "format"s, like format a disk, or format of some documents, in excel, in .net, ...
At least found some references for "###" instead of "@@@"...

Re: Wrong result on format($i, " 0")

Posted: 10 Jan 2012 10:39
by admin
PeterH wrote:You are right: format($i, "@@@") returns what I want! Thanks!

Maybe you should add it as second example to the documentation of format function? (Direct behind "000".)
So if I name it "bug" it's a "lack-of-documentation bug" :wink:

If you use an MS-function, and they do provide some documentation, could you add a reference, too?
I just tried Google - but fount only other "format"s, like format a disk, or format of some documents, in excel, in .net, ...
At least found some references for "###" instead of "@@@"...
I try to avoid referencing to MS pages because they change their URLs as crazy.

Re: Wrong result on format($i, " 0")

Posted: 10 Jan 2012 10:47
by PeterH
admin wrote:I try to avoid referencing to MS pages because they change their URLs as crazy.
Ah - bad.

So please just add this "@@@"-example to help.

And thanks anyway!

Re: Wrong result on format($i, " 0")

Posted: 10 Jan 2012 10:55
by admin
Yep, help done. :)