String.Mid(n)

If I have:

ofxDateString = "20141111" myString = ofxDateString.Mid(1,4)

i would expect myString to be “2014”. I though Mid(x,y) where x is start position and the first character was position 1.

In the above example I have to use ofxDateString.Mid(0,4) to get myString = 2014, is this correct?

Also once extracted I want to assign the 2014 to the year property of a date object, would you advise Val i.e.:

myDate.Year = Val(myString)
ofxDateString = "20141111"
myString = ofxDateString.Mid(1,4)

or

ofxDateString = "20141111"
myString = Mid(ofxDateString,1,4)

or

ofxDateString = "20141111"
myString = Left(ofxDateString,4)

should all result in “2014”

I believe this is a bug, can someone confirm. I put the following code in the open event of a window:

Dim myText as Text = "123456789" MsgBox myText.Mid(1,4)

The resulting message is “2345” but I believe it should be “1234”

That’s not a bug- the new framework (like the Text type) is consistently 0-based.

If you define it as STRING it works as expected… as TEXT it returns 2345

BUT… Mid(myText,1,4) returns “1234” regardless if STRING or TEXT

[quote=157841:@Dave S]If you define it as STRING it works as expected… as TEXT it returns 2345

BUT… Mid(myText,1,4) returns “1234” regardless if STRING or TEXT[/quote]

What you’re seeing when calling the global function Mid is that the Text is implicitly being converted to a String and you’re ending up with the String behavior.

Right so massively confusing then.

No thats fine now I know and yes Travis it is more consistent. I never understood why it was position 1 when everything was made zero based a few versions ago.

The alternative is for the conversion from Text to String be explicit and any place you need a String and have a Text you’d have to do something like String.FromText(myText). Maybe that would have been a better direction to go, maybe not.

Will string be deprecated in the future. I have started using Text in all my new development instead of string, is this the way to go?

Yes, but the future is at least five years out.

For model classes and non-UI classes in general, it’s not a bad idea. It will probably lead to some ugly edges where you have to interoperate with code using String. There’ll be more APIs using Text in the future, but right now there’s not many.

Yes this is what I am finding