04-17-2010, 07:45 PM
I cannot understand the reason of some errors I'm getting about converting a string into a value and a value into a string.
In order to debug, I wrote a simplified version of the code:
stringIf is a simple alternative to the Sinclair Basic use of AND with strings:
So I can port it this way:
I don't understand why the following line fails:
I tried an alternative, but nothing changed:
Beside those simple tests, I did several tries in the original code, and noted "FINE" or "ERROR" (all variables are DIMed as ubyte):
One of the tries caused both errors at the same time (string into value and vice versa!):
The stringIf function is defined to return a string, so I cannot understand what's the problem.
I tried another thing... Maybe it has to do with concatenation... Let's see:
it compiles! So the problem has something to do with string concatenation.
I'm stuck. I need some enlightenment.
In order to debug, I wrote a simplified version of the code:
Code:
dim a as ubyte
let a = 10
print "Yes: "+stringIF(a,"yes")+"..." ' ERROR: Cannot convert string to a value. Use VAL() function
print "Nothing: "+stringIF(0,"yes")+"..."
stop
function stringIf(condition as uinteger,text as string) as string
if condition then
return text
else
return ""
end if
end function
stringIf is a simple alternative to the Sinclair Basic use of AND with strings:
Code:
LET A$ = "string" AND condition
So I can port it this way:
Code:
let aString = stringIf(condition,"string")
I don't understand why the following line fails:
Code:
print "Yes: "+stringIF(a,"yes")+"..." ' ERROR: Cannot convert string to a value. Use VAL() function
I tried an alternative, but nothing changed:
Code:
dim a as ubyte
dim t as string
let a = 10
let t = "Yes: "+stringIF(a,"yes")+"..." ' ERROR: Cannot convert string to a value. Use VAL() function
let t = "Nothing: "+stringIF(0,"yes")+"..."
stop
Beside those simple tests, I did several tries in the original code, and noted "FINE" or "ERROR" (all variables are DIMed as ubyte):
Code:
#define true 1
tell("Son las "+str(currentHour)+stringIf(currentMinute<>0,":"+stringIf(currentMinute<10,"0")+str(currentMinute))+" de la noche.") ' ERROR : Cannot convert string to a value. Use VAL() function
print "Son las "+str(currentHour)+stringIf(currentMinute<>0,":"+stringIf(currentMinute<10,"0")+str(currentMinute))+" de la noche.") ' ERROR : Cannot convert string to a value. Use VAL() function
print "Son las "+str(currentHour) ' FINE
print "Son las "+str(currentHour)+str(currentMinute)+" de la noche." ' FINE
print "Son las "+stringIf(currentMinute<>0,":") ' ERROR: Cannot convert string to a value. Use VAL() function
print "Son las "+stringIf(true,":") ' ERROR: Cannot convert string to a value. Use VAL() function
print stringIf(true,":") ' FINE
One of the tries caused both errors at the same time (string into value and vice versa!):
Code:
#define true 1
dim temp as string
' the following line gets two errors:
' Cannot convert value to string. Use STR() function
' Cannot convert string to a value. Use VAL() function
let temp = "Son las "+stringIf(true,":")
print temp
The stringIf function is defined to return a string, so I cannot understand what's the problem.
I tried another thing... Maybe it has to do with concatenation... Let's see:
Code:
print "Yes: ";stringIf(a,"yes");"..." ' FINE
it compiles! So the problem has something to do with string concatenation.
I'm stuck. I need some enlightenment.
Marcos Cruz
http://programandala.net
http://programandala.net