DIM and INT

When I use
local n
let n=int(4.01)
then DIM x(n)
TB 5.41 returns n must be an integer. n should be an integer.

What am I doing wrong ?

Bob Brannock

Comments

Books

Hi Bob,

Finally after dragging my feet a bit, my World Tour of TrueBASIC book is near completion (458 pages so far). In the meantime I have also written 10 other novels - all available from Amazon under the pen name J.Randolf Scott.

Regards
BigJohn

re: dim and int

Not sure why this is the case, but you need to dimension your array normally first, then you can redimension it with your statements.

local n, x(2)
let n = int(4.01)
mat redim x(n)
let x(3) = 5
print x(3)
end

This works (added the test to be sure the array had actually been redimensioned.) If I remember correctly, you always need to do this if you are setting dimensions through a variable. The initial dimensioning is just a dummy value. So even if you had said let n = 4 and then dim x(n) it wouldn't work. So the bottom line is to set an initial dummy dimension statement and then the MAT REDIM using the variable.

rwt

Thank you

Thank you Master Physics Prof. Works great. I always enjoy your comments and BigJohn's also. I like your website also.

Bob B.