"Unable to convert from String to Int"

BlitzMax Forums/BlitzMax Beginners Area/"Unable to convert from String to Int"

sswift(Posted 2006) [#1]
Blitzmax gives me the above error on this line:
Sudoku[SudokusLoaded, X, Y] = Mid$(ThisLine$, N+1, 1)

It allows this however:
Sudoku[SudokusLoaded, X, Y] = Int(Mid$(ThisLine$, N+1, 1))

Why is it giving me this error? The docs clearly say that converting from a string to an int can be done automatically without explicit type casting.


Michael Reitzenstein(Posted 2006) [#2]
I think this changed in Strict mode in the last update.


Azathoth(Posted 2006) [#3]
Or use the method ToInt()

Sudoku[SudokusLoaded, X, Y] = Mid$(ThisLine$, N+1, 1).ToInt()


N(Posted 2006) [#4]
Why is it giving me this error? The docs clearly say that converting from a string to an int can be done automatically without explicit type casting.


Rule of thumb: don't trust the documentation.


sswift(Posted 2006) [#5]
Crow:
It works in other circumstances, like when using print "value =" + X, so if it works in some instances and not others, that's a bug.

Michael:
I'm not running in strict mode.

Aza:
Int() requires less typing, and less silly object oriented craziness.


tonyg(Posted 2006) [#6]
I don't understand your working example.
Print "Value = " + X
How did you populate X?
Isn't this...
x="Hello"
Print x

the clincher?
Where in the manual does it say it'll convert automatically. Maybe that's what needs changing?


sswift(Posted 2006) [#7]
x is an integer. Ie, the number of milliseconds it took to solve the sudokus. Print("Solved in " + Time_to_Solve + " milliseconds.") where Time_to_Solve is an integer, works just fine.

Where does it say it does this in the manual?
Help->Language->Types


The following type conversions are performed automatically by BlitzMax when necessary - for example, when assigning an expression to a variable, or when passing an expression to a function:

Source type Target type
Integer Floating point, String
Floating point Integer, String
Object Base object
Object Byte pointer
Array Byte pointer, ElementType pointer
Function Byte pointer
Pointer Byte pointer



Speaking of solving time, I just tested my sudoku solver and it takes 388 seconds in Blitzmax, and 417 seconds in Blitzplus, to solve 1465 sudokus. That's not a very large speed increase.

There's a few things I learned about arrays today which might allow me to make a few speed gains, but since Bmax was 2x faster at accessing arrays in my tests today, and my solver is not even close to 2x faster now, I don't think I will see great speed improvements from optimizing array accesses.


Michael Reitzenstein(Posted 2006) [#8]
It works in other circumstances, like when using print "value =" + X, so if it works in some instances and not others, that's a bug.

No, one is converting from string to int, the other from int to string. Logically you can convert from int to string safely, but not the other way around.


sswift(Posted 2006) [#9]
Michael:
You're right. I see now. The help file doesn't say you can convert string to int without typecasting, only int to string. So that's why I can't do x = mid$().

In my defense though, Mark got me into this bad practice by allowing me to do it all this time in other versions of Blitz. :-)