Integer.fromText

a = integer.fromText("-1") -> ok
a = integer.fromText"+1") -> xojo.core.bad.data.exception

???

[quote=153222:@Gilles Rioux]a = integer.fromText("-1") -> ok
a = integer.fromText"+1") -> xojo.core.bad.data.exception

???[/quote]

You are missing the opening parenthesis :
http://xojo.helpdocsonline.com/integer$FromText

Assuming you actually had the parentheses in real code this might be a valid exception from Xojo’s point of view. “-1” is really negative one. “+1” is probably considered an unknown string since it’s not common to have positive numbers with the + in front of it.

Integer.FromText is very stringent and there was a very ‘healthy’ debate on it over the weekend here on the forums https://forum.xojo.com/18207-what-do-you-think-of-the-new-framework and on my blog http://www.bkeeneybriefs.com/2014/12/new-xojo-framework-thoughts/.

The bottom line is that 2015 R1 will probably have an Integer.Parse method that would allow this. Until then you’ll want to strip the + sign out of your string.

[quote=153252:@Bob Keeney]Assuming you actually had the parentheses in real code this might be a valid exception from Xojo’s point of view. “-1” is really negative one. “+1” is probably considered an unknown string since it’s not common to have positive numbers with the + in front of it.
[/quote]

Although the usage is uncommon, “+1” is by definition a valid text representation of the number 1. A bug report should be filed… If the are going to be very strict, they need to follow all the rules too!!!

That said, unless there is a speed issue with *.Parse, I doubt I’ll ever use *.From text of numeric conversion.

That said i REALLY hope they code *.parse efficiently under the hood … Anybody remember the first implementation of Join(string())? The way it was coded is was about as slow as doing:

Dim JoinedString as String For Each Item as String In StrArr JoinedString = JoinedString + Item Next

And we all know how slow that is because of immutable strings!

I hope they do some significant optimization on *.Parse from the start as people like me call Val a lot when parsing data files!!!

I will certainly test it relative to the execution speed of Val.

  • Karen

[quote=153230:@Michel Bujardet]You are missing the opening parenthesis :
http://xojo.helpdocsonline.com/integer$FromText[/quote]

This was not copied from IDE, but typed from my memory, my mistake.

But in this case, I should have got a syntax error at compile time and not a runtime error ?

[quote=153404:@Gilles Rioux]This was not copied from IDE, but typed from my memory, my mistake.

But in this case, I should have got a syntax error at compile time and not a runtime error ?[/quote]

Indeed.

[quote=153404:@Gilles Rioux]This was not copied from IDE, but typed from my memory, my mistake.

But in this case, I should have got a syntax error at compile time and not a runtime error ?[/quote]
No. The compiler doesn’t look at the value of the text, but the function does at runtime. Hence the “runtime” error.

I just run this: dim a as integer = integer.fromText"+1")
and I got that from the compiler : [quote]Not enough arguments: got 0, expected 1[/quote]

But with this: [quote]dim a as integer = integer.fromText(“+1”)[/quote]
it compile nice but fail at runtime with a “Character ‘+’ is not a valid number” reason.

[quote=153641:@Gilles Rioux]dim a as integer = integer.fromText(“+1”)
it compile nice but fail at runtime with a “Character ‘+’ is not a valid number” reason.[/quote]

When I do that on Mac I get

No error with “1” or “-1”

Looks like a bug worth reporting. In the meantime, why not do :

dim t as text = "+1" dim a as integer = integer.fromtext(t.Replace("+",""))

Since by definition, a numerical value without + is positive.

Thank you Michel. I will do that.