"dim"

In this little program the result is an error saying that in the "dim" line the "e" should be an integer.

input n
print n
let e = int(n)
print e
dim y(e)

end
Why is the variable "e" in the "dim" statement not recognized as an integer? Is there a workaround?

Comments

dim argument

Yes, the "e" should be an integer VALUE, NOT a NUMERIC VARIABLE, which is what your "e" is. You don't need a "workaround".

The syntax for using the DIM statement is:

DIM y([a numeric VALUE, not a VARIABLE]), such as DIM y(0)
This simply declares the variable "y" to be a numeric array. (Or DIM y$(0), if the array elements are to be strings.)

Then, to apply some value other than the "0" in this example, one must use:

MAT REDIM y([some other INTEGER VALUE, OR a NUMERIC VARIABLE])

Thus your little program could be:

input e
print e
DIM y(0) ! or any other numeric integer VALUE; e.g., DIM y(43) etc.
MAT REDIM y(e) ! NOW the "0" (or whatever) is changed to whatever the value of "e" is.

END

I recommend that you download the TB Silver PDF manual from the "Downloads" section on the TB page. It doesn't matter what version of TB you have, the inner workings of all TB versions are exactly the same, and so the manual will cover everything that can possibly be done with True Basic.

Hope this helps.
Regards, Mike C