sub main()
Dim s as String
Dim b as Byte
dim i as byte
s = "Howdy"
b = asc(s)
debug.print b
debug.print
b=asc(s,1)
debug.print b
b=asc(s,2)
debug.print b
debug.print
for i = 1 to 2
b=asc(s,i)
debug.print b
next
end sub
.
On my Zx1280 this produces:
ZBasic v2.6.3
72
0
0
72
111
in other words a directly entered index in Asc(string, index) doesn't work but a variable does.
I presume (perhaps dangerously) it's not meant to work that way
deadmm wrote:I presume (perhaps dangerously) it's not meant to work that way
Indeed not. The output is the result of a code generation optimization problem that has now been corrected.
When the compiler can determine both the string content and the specified index (if any) at compile time it may substitute the resultant value instead of generating the code to effect the function call. There was a coding error in the compile-time evaluation of the index value that caused the compiler to conclude that the result would be zero, hence the observed output.