PDA

View Full Version : [SOLVED:] loading array with dates



DBinPhilly
04-08-2019, 04:04 AM
I'm trying to load an array with a series of dates. I keep getting a 'subscript out of range' error, which I assume means that the date is coming in the wrong format, maybe?
The data being read (we!WEdate) is a date format field.

Here is my code:

Option Base 1
'define the array
Dim A() As Variant, i As Integer
A = Array(52)
____________________________________________
'after defining the database and recordset:

we.MoveFirst
i = 1
rewe:
If we.EOF Then GoTo Donewe
A(i) = we!WEDate
i = i + 1
we.MoveNext
GoTo rewe
Donewe:
we.Close
_____________________________________________________
I've also tried this:
A(I) = "#" & we!WEDate & "#"
_____________________________________________________

what am I doing wrong? It's been years since I've worked with arrays, because I do very little development work now.

OBP
04-08-2019, 06:57 AM
It could be that you need to redim the array before filling it.
This works for me

Dim A As Variant, i As Integer
ReDim A(0 To 5) As Variant
A(0) = Date
A(1) = Date + 1
MsgBox A(0) & " " & A(1)

DBinPhilly
04-08-2019, 07:08 AM
OBP:
Yes, that works. Thanks a lot.

OBP
04-08-2019, 07:17 AM
:thumb :thumb