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

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
Post Reply
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

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

Post 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 :? )

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 67332
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

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

Post 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.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

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

Post 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 "@@@"...

admin
Site Admin
Posts: 67332
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

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

Post 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.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

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

Post 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!

admin
Site Admin
Posts: 67332
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

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

Post by admin »

Yep, help done. :)

Post Reply