Except, if... Dim MyArray(1 to 100)
then... Elems = Ubound(MyArray) - Lbound(MyArray)
won't give us the number of elements in the array.
We need to... Elems = Ubound(MyArray) - Lbound(MyArray) + 1
"Suffice it to say that adding disk drives and a disk operating system to a personal microcomputer is guaranteed to increase its power dramatically." CP/M and the Personal Computer
That's right, since I guess you would want a counting number instead of a base 0 number... It all depends on what you are trying to do...
in DIM Array(3)...
Array(0) : element 1
Array(1) : element 2
Array(2) : element 3
Array(3) : element 4
maxIndex = 3
maxElem = 4
For simplicity, I usually stick with a zero base array...
Then just use Ubound to get the max index...
if you need to show the max NUMBER OF items...
Just add 1 to the Ubound... PRINT "# of Items:" + Str(ubound(array) + 1)
One thing to keep in mind is that from the begining of the design of a program... you your program to be able to run as fast as possible... every math operation you leave out will (all together) make your program run faster...
This is especially important if you are dealing with graphics...
Yes computers are very fast, and it seems as though it takes no time at all to complete a math operation...
Thus because the calculation are comleted on a scale of milliseconds... but lets say, for example, it takes .005 seconds to add or subtract, and .010 seconds to multipy or divide...
For a single operation, you would not be able to even see the wait... but when you are doing a series of 10,000 calculations, and each calc has say 2 additions, and 1 divide... that would take .020 seconds * 10,000 , which would be 200 seconds, or aprox. 3.3 minutes...
where if you had only one additiom operation per calc, it would only take 100 seconds and cut the time in half...
the above clock ticks per operation are a bit exagerated, but you can get an Idea of why you want to cut your math operations to a minimum...
No one likes to wait for a program to update... No matter what kind of program it is... And when you get into complex situations, (which any program *CAN* have a potential to have, whether from the start, or later adding a GUI, etc...) every operation counts...
It is best to practice and develop habits for optimizing your code from the start as opposed to many headaches later on down the road...
Remember it is always easier to throw in a delay routine than to comb out all of the slow routines through out your entire program to speed it up...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.