Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there any way to create a DIM with variables?

I'm trying this

DIM variableName( 20 * ( myVariable + 1 ) ) AS UBYTE

but the compiler says : "Array bounds muts be constants"

Is there any way to create a DIM with variables?

With a Basic variable?

Unfortunately not yet. These are DYNAMIC variables. I'm currently working on that feature. :roll:
You can, however do a "dirty trick" of allocating a dynamic block of memory (with alloc) and then use PEEK / POKE on top of it (similar to a C ptr).
I will post then it's ready.

Well i was not asking for something complicated Smile

Now i "resolved this" by doing a #DEFINE

Not is a variable, but for the purpose of the problem is good enough Smile

i made this per example


DIM variableName( 20 * (SOMENAME + 1 ) ) AS UBYTE

This works enoug for me Smile
Well, you can also use CONST to define a value, and use them in an array definition

const cols as Uinteger = 32
const rows as Uinteger = 24
dim a(rows, cols) as Uinteger

Rows and cols cannot change. They're constants. So this is allowed. 8)

Forum Jump:

Users browsing this thread: 2 Guest(s)