-
I get error "subscript out or range" with the following code.
Code:
Dim sSQL As String
Dim aryData(1, 5)
Dim n As Integer, i As Integer
sSQL = "SELECT * FROM Oxygen " & _
"WHERE pond = 'A1A'"
Set rsoxygen = GetRecordSet(sSQL)
i = 0
For n = 4 To 14 Step 2
aryData(0, i) = aryData(0, rsoxygen(n))
aryData(1, i) = aryData(1, rsoxygen(n + 1))
i = i + 1
Next
-
It seem to me that your array is not big enought to hold the data want to put it in, it is dimensionised as (1,5) but you are trying to put 7 items in it (4 to 14 step 2, those are 7 items)...
-
4,6,8,10,12,14 is 6 not 7
This seems to work. But I get "bad function argument" when I try to use it to load mschart which is why I needed that array in the first place.
Code:
For n = 4 To 14 Step 2
aryData(0, i) = rsoxygen(n)
aryData(1, i) = rsoxygen(n + 1)
i = i + 1
Next
MSChart1.ChartData = aryData
-
Why not do it this way?
He's right, but here is another option...
------------- JUST AN OPTION -------------
I have used Arrays in my code all the time. But I think you might want to see if this way "suits your fancy".
The ADO Recordset object has two methods that allow you to retrieve the information from the recordset in two formats.
1) Array format = oRS.GetValues
2) String format = oRS.GetString
The first (1) is the way you want to get the information.
Code:
Dim oRS as ADODB.Recordset
Dim sSQL as string
Dim vValues as variant
ssql = ""
ssql = ssql & "Select LastName, FirstName from Names Where State = 'CA'"
Set ors = new adodb.recordset
ors.open ssql, oConn, adForwardOnly, adReadOnly
vValues = ors.GetValues(x) ' If you put a value here for
' x, you will get that many records back. Otherwise
' leave it out and it will return all records.
if not ors is nothing then ors.close
set ors = nothing
Now you can look at the vValues array as vValues(Row, Field) (or its the other way around; can't remember off the top of my head)
This is a very fast way of doing what you are already intending on doing with your other code.
Have fun experimenting.
-
My mistake
I am sorry to have given you some back code. Please change the previous statement of
1) Array format = oRS.GetValues
2) String format = oRS.GetString
to
1) Array format = ors.GetRows
2) String format = ors.GetString
Sorry about that.