Text to string in an if statement

If I have:

Dim mytxt as text, mystr as string
then to convert between them I can say either of:

mytext = mystr.ToText mystr = mytext

What about in an if statement? Specifically if f’rinstance I have:

mytext = "0800"
and I want to do something like:

if (cond1 and cond2 and IsNumeric(mytext)) then // this will fail as IsNumeric requires a number as a String, not a Text end if

However this seems to work:

if (cond1 and cond2 and IsNumeric(str(mytext))) then // this appears to behave as desired end if

My question: is using str() to convert a Text to a String something I can rely on?

Well, we’re not sure if the Text datatype is long for this world since API 2.0 might move away from it.

Wouldn’t API 2 backward support existing code that uses Text?

it is sounding like a lot of the “new framework” will be removed completely (my understanding)… which is why it is being recommended to start “un-using” it now

I’m just wondering if I need to start refactoring my use of Text in current projects. I had refactored my use of String previously because I was anticipating having to do that for the New Framework.

I’ve heard no announcements at all, apart from “There is API 2.0”. For all I know, that could mean we’ll all be using Fortran IV in a couple of years.

No official word on anything regarding Text, Auto, and the new API 2.0 framework. Personally, I’d stick with String until we get definitive word from Xojo on this.

Meanwhile, what about my OP?

After reading IsNumeric, Text and MsgBox, I think that IsNumeric has a bug, or the docs need an update.

IsNumeric page doesn’t mention Text.
Text has a Sample Code section and the second sample say: “Text is available in all project types, so you can also use it in place of String. A Text value can be converted to a String, so code like this works:

Dim t As Text = "Hello, World!" MsgBox(t) ' MsgBox takes a String, but this works because Text can be converted to String
after reading that I expect Text to be converted to String as needed
MsgBox (used on the previous sample) docs page say “Displays message box showing the string passed.”, there is no mention of Text passed to it.

I think is safe to use str(myTxt) to convert your Text variable to String variable and use it on IsNumeric, but I’m no expert.

No, it is not. The Xojo framework is deprecated but will stay for a long time. iOS still demands the Xojo framework and has not yet rebuilt to the classic or API 2.0.

Did you read Xojo 2018r4 Release Notes (concerning API 2.0) ?

Read the URLConnexion entry.

hence the caveat (my understanding) :slight_smile:

I read the keynote recap but it didn’t tell me much. New APIs. What does that mean? I’d like to think we get to one framework, presumably the old one, with improvements from the new one ported back to the old. Perhaps SpecialFolder.GetResource, new in 2018r2, is an example of this.

Perhaps we can start a new thread here if people want to continue debating how Xojo Inc should proceed with API 2, as we seem to be moving far away from the OP’s query. In the mean time,

IsNumeric(str(mytext))

seems like a reasonable solution to his post. No?

I’d love a thread about that but I don’t feel I know enough about API 2.0 to start one.

[quote]

IsNumeric(str(mytext))

seems like a reasonable solution to his post. No?[/quote]

Meanwhile this is indeed what I’m doing.