hatman...thanks for your continued help...glad this stuff is easy for you...ha...
nothing more than repitition in programming languages before I found VBA burind in Excel for the first time
let me see if my understanding of what you are trying to do is correct...
Code:
ReDim arr(1 To 2, 0 To 1)
arr(1, 0) = 1
arr(2, 0) = 1
declarring arr with the first dimension (see i didn't use row) from 1 to 2 (so essentially 2 sets of data)
and the second dimension from 0 to 1.....this is essentially because the next two lines are setting the first data point in each of the 1st dimension to 1....which in the next part will compare to the ubound of the 2nd dimension?
i assume this code would need to go where ever i need the array initialized?
yes to everyting to this point
wait i "think" the light bulb went off...then it started to go out again...let me try to see what's what...
Code:
arr(1, 0) = arr(1, 0) + 1
above in the module we set arr(1,0)=1 so we're adding 1 + 1=2
assume using this as a counter?
yes, I am using the arr(n,0) positions to keep track of the last user defined data point in each data set. It eliminates the need for the Forr..Next loops, which would impact performance in VERY large arrays... but that's a side effect of my attempt to eliminate the need to designate a flag in the data set.
Code:
If arr(1, 0) > UBound(arr, 2) Then
at this point arr(1,0)=2 and ubound(arr,2) =2 (i assume 0 to 1 would make the ubound 2)
[/code]
No, on the first pass Ubound() is equal to 1. Ubound is very different than the .Count property (Method? can't remember) of VBA collection objects. The Ubound() function always returns the numerical value of the ordinate in the specified dimension. In other words, Ubound(arr,1) where Arr(10 to 50) is 50.
that would be false so it skips the redim preserve at this point...
nope, it executes the Redim Preserve for reason stated above
Code:
arr(1, arr(1, 0)) = arr(1, arr(1, 0) - 1) + adder
this is the line that i think is losing me (assuming i'm not lost already)
arr(1,0)=2 so arr(1,2)=arr(1,2-1)+adder
so we are storing into arr(1,2) the value of arr(1,1)+adder
i don't understand where we got arr(1,1)...also what happened to arr(1,0)?
In re-reading some of our dialogue, I see that I assumed that you are wanting to performan arithmetic addition, when you may be using the term Add to mean Populate. I will continue on my assumption until you set me straight.
Arr(1,1) is zero. When a numerical array is initialized, all values are 0 until you set them to be something else. When I put this code together, I had to maintain the zeros in th efirst position of the array (arr(n,1)) due to my assumption that you wanted to perform an arithmetic addition. I did this by assigning arr(n,0) = 1. And this may very well be my bad. if you want to populate he user input into the array, rather than adding it to the previous value, then you would leave arr(n,0) as their initial value of 0, and do
Code:
arr(1, arr(1, 0)) = adder
rather than
Code:
arr(1, arr(1, 0)) = arr(1, arr(1, 0) - 1) + adder
So what happened to arr(1,0) you ask? Nothing. It's a counter that indicates the last ordinate of the second dimension where user data is stored in arr(1,n). We leave it alone for now, and use it as a pointer the next time the routine is called to immediately move to the proper location in the array, without the need to parse for a flag.
ps...i read your next post and that is what i had in mind to combine...thanks...
I didn't want to throw it at you too soon, because it's yet another level of indirection.
I made this code lean an mean... feel free to pop in some Watches or A=ubound(arr,2) to see how things behave in break mode.