Type Conversion

BlitzMax Forums/BlitzMax Beginners Area/Type Conversion

Mental Image(Posted 2007) [#1]
In BlitzPlus, I can do implicit type conversion like this:

Global current_year=Right$(CurrentDate$(),4)


which, I suppose, is equivalent to:

current_year=val(Right$(CurrentDate$(),4))


in older basic dialects.

What do I do in Max, and are there other rules for similar type conversions - I am trying to convert a large Blitzplus application to Max, and it is hard work!


tonyg(Posted 2007) [#2]
Global current_year:String = Right$(CurrentDate$() , 4)
no...really it is.
<edit> or
Global current_year:Int = Int(Right$(CurrentDate$() , 4))



Mental Image(Posted 2007) [#3]
Thank you, Tony, that helps enormously. I should know all this, but haven't been using MAX for over a year. The second one is what I was after.


tonyg(Posted 2007) [#4]
np
<edit> start again... It's advisable to define every variable/object so run with SuperStrict defined.


FlameDuck(Posted 2007) [#5]
Or more generally
Global myString:String = CurrentDate$()
Global current_year:Int = myString[myString.Length-4..].toInt()
or since you know that CurrentDate is always going to be a certain size:
Global current_year:Int = CurrentDate$()[7..].toInt()