New Framework Integer to Text is maddening

So in the old framework, if I want to output an integer to a string padded with zeros, this was pretty simple:

Dim Value As Integer = 5 MsgBox(Str(Value, "00"))

In the new framework, the code looks like

MsgBox(Value.ToText(Xojo.Core.Locale.Raw, "00"))

These two do not work:

MsgBox(Value.ToText("00")) // It is insane that this is not allowed. MsgBox(Value.ToText(Nil, "00"))

Couldn’t you just use

MsgBox(Format(Value, "00").ToText)

(although it would be nice to have the ToText(“00”) directly)

No, Format is part of the old framework and not available in all projects.

That’s what I get for only checking it in desktop. :frowning:

Rule of thumb is that if it is global, it is probably from the old framework. There are exceptions though, at least according to the docs.

The new framework is definitely going to result in some.very.long.statements which I can see making.readability.much.worse.

They could have at least dropped the leading Xojo. to make things slightly shorter.

I don’t have a problem with that, and it’ll be nicer once Using is respected by autocomplete. Until then the Using feature is nearly useless, so we have a lot of typing to do.

Forgive the possible ignorance here, but doesn’t this issue get solved by using your own personal wrapper function?

Sure, but that shouldn’t be necessary. Besides, I’m not trying to make the new framework like the old framework. I’m pointing out areas where the new framework doesn’t make sense. Why on earth is Integer.ToText(“00”) not allowed, but Integer.ToText() is allowed? Both use an implied locale.

OK, makes sense, I understand your context.

I was just reacting to the Gale response “The new framework is definitely going to result in some.very.long.statements which I can see making.readability.much.worse”, which isn’t true FOR THE PROGRAMMER. Maybe for the designer.

If I do

Dim i as integer MsgBox i.ToText

then I don’t see an optional format in the hint. Is it shown for you?

[quote=186723:@Thom McGrath]
These two do not work:

MsgBox(Value.ToText("00")) // It is insane that this is not allowed. MsgBox(Value.ToText(Nil, "00"))[/quote]

Nil I can understand as its not a valid locale
The previous one I’m not so sure about - it seems perhaps an oversight that its not possible

However you can do

MsgBox(Value.ToText(Xojo.Core.Locale.Raw, "00"))

(or swap Current for Raw) which is kind overly verbose but does what you need at the moment

See case <https://xojo.com/issue/39312>

This falls in with the “Auto” thread
What you see now is not all there ever will be so asking for the additional overloads is reasonable (at least to me)

Hehe, thanks Norman. My original message already pointed out that the very verbose option works.

[quote=186723:@Thom McGrath]In the new framework, the code looks like

MsgBox(Value.ToText(Xojo.Core.Locale.Raw, “00”))[/quote]
The reason I suspected Nil might work is because the docs say the parameter is optional, so it seemed like a potential option. It probably shouldn’t work, but it was worth a shot.

To me, it seems like Value.ToText(“00”) should work, but the compiler gets confused. And I know the new framework is not done, that’s why this stuff is worth talking about.

Hence the case I filed
It would seem that there should be 4 possibilities
no params
locale only
format only
locale + format

a locale passed as NIL seems like it should revert to using the raw locale
We’ll need to review as whats there meets the original spec which was intentionally functional but minimalist

Yeah, I read the case. All good things. If I wasn’t on my phone, I’d add that the docs should define which locale is used when one is not supplied. That may even be a separate case.

Xojo.Core.Locale.Raw I believe
But you’re right it doesn’t say which in the docs

Yes, it uses Locale.Raw. I’ve updated the pages with that info.

It’s also very frustrating that I can’t do something like

Dim Message As Text = "Found " + (UBound(Results) + 1).ToText + " results."

Unless I’m mistaken, the only thing I’ve found that works is

Dim Message As Text = "Found " + CType(UBound(Results) + 1, Integer).ToText + " results."

Which feels very terrible.

Parenthesized expressions :frowning:
Its right in the grammar for the language - not trivial to fix unfortunately.

However

Dim Message As Text = "Found " + UBound(Results).ToText + " results."
would work but its not the result you’re looking for

Odd but true
Its been this way since about RealBasic 5.x

And yes, looking at the grammar, CType will work

I know it’s not a new behavior, just more relevant now because the new framework relies on extension methods very heavily.