Thread: Arrays
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
David David is offline
external usenet poster
 
Posts: 1,560
Default Arrays

Hi,
Thanks for your response. This is what I have so far, but it is not yielding
what I expect still:
Dim CloseChanges() As Date, ThisDate As Date, ThisClose As Double
ReDim CloseChanges(YearsTotal)
For y = 1 To YearsTotal
ThisDate = ActiveCell.Value
ThisClose = ActiveCell.Offset(0, 6).Value
ActiveCell.Offset(-52, 0).Select

Next y
Stop

After the stop I go to the immediate window and type:
?ThisClose(1)
I am expecting the data stored in the Array to now be available to me, but I
get:
"Compile Error:"
"Expected Array"

The Option Base is set. In the Immediate Window, if I type ?CloseChanges(1),
wht I get is 12:00:00 AM. It does not matter which number I try and access,
it is alway 12:00:00 AM.

ThisDate
and
ThisClose
Are the elements I need to access.

Thanks,
David
"Douglas Klimesh" wrote:

To start with you you are not declaring CloseChanges() as Date. Use instead:
Dim CloseChanges() As Date, ThisDate As Date, ThisClose As Double

Also, note that by default arrays are dim'ed starting with 0. So if you
ReDim CloseChanges(10) the array is actually CloseChanges(0) ..to..
CloseChanges(9). Use the directive Option Base 1 at the very beginning
of your module code to have an array that goes from 1 to 10 instead of 0
to 9. Or you could: ReDim CloseChanges(1 To YearsTotal)

I always use Option Base 1 because if there is an problem with my index
variable its value will most often be zero, which will give me a VBA
error and more obviously alert me to my programming problem.

David wrote:
hi Group,

I am have a hard time with the syntax for setting up an Array.
This is what I have so far:
Dim CloseChanges(), ThisDate As Date, ThisClose As Double
ReDim CloseChanges(YearsTotal)
For y = 1 To YearsTotal
ThisDate = ActiveCell.Value
ThisClose = ActiveCell.Offset(0, 6).Value
ActiveCell.Offset(-52, 0).Select

Next y
It did not like that I was using a variable to start with, so I went to the
ReDim syntax, but it still does not like it. The Array has only 2 data points
it is trying to pull in.

After it runs, I went to the Immediate Window and tried this:
?ThisClose(1)
But I get a message "Expect Array". Not sure wherre I am going wrong?

Thanks,
David