UBOUND Upper boundary of an Array. A work-around
Modified on 2016/12/17 19:55 by CaptainBoing — Categorized as: Arrays
Common in the Microsoft Basics, UBOUND() returns the number of the highest array element, i.e. the value specified in DIM and vital for working with dynamic arrays. A proper function is difficult to emulate because of the problem of not knowing the type of array passed in to any argument - you would need a function for each type. I suspect there are probably methods surrounding PEEK and the VAR table but I have not explored these.
The easiest (fastest) method I have found is to track the array size with a variable:
x_top=20 DIM x(x_top)
this is small overhead and although it isn't an emulation, so long as you track the size in myvar it will survive ERASE/DIM combinations.