-
Problem w/ Arrays
When I define the array arData as below, I receive a type mismatch error when I try to assign a recordset to it using the GetRows Method: arData = RS.GetRows()
If I define the array like: Dim arData, I get a "Subscript out of range: aValues" error. aValues is the "arData" parameter for ShowChart. ShowChart loops through the array and retrieves all of the values and builds a bar graph, but it is having problems using an index w/ arData.
If anyone can help me out, I would appreciate it.
Code:
Public Sub CreateChart()
Dim i
Dim arData(100) 'Array For Values
Dim arLabels(100) 'Array For Labels
Set Conn = Server.CreateObject("ADODB.Connection")
With Conn
.CursorLocation = aduseclient
.CommandTimeout = 15
.Open CONN_STRING, UserID, PSWD
End With
SqlStr = ""
SqlStr = SqlStr & "svc_rec_online_BarChart "
SqlStr = SqlStr & "@Rec_From_Date='01/01/01', "
SqlStr = SqlStr & "@Rec_Thru_Date='7/03/01'"
Set RS = Conn.Execute(SqlStr)
arData = RS.GetRows(adGetRowsRest, adBookmarkFirst, "Total")
arLabels = RS.GetRows(adGetRowsRest, adBookmarkFirst, "rec_month")
Set RS = Nothing
Set Conn = Nothing
'Create Barchart
Call ShowChart(arData, arLabels, "Title", "X", "Y")
End Sub
Thanks In Advance,
Chris :(
-
Try doing:
Code:
Dim arData As Variant
Dim arLabels As Variant
Then when you pass GetRows into them, they will become arrays.
-
That gave an error "Expected End of Statement". I was unaware that you could define variable datatypes in VBScript. Do I need to include a file into my asp page? Any other suggestions?
Chris
-
Yes, you can't declare the variable as an array before you assign a record set to it. It is the same quirk as assigning the output of Split() to an array, can't do it.
I think that has to do with how = works.
Anyway... it smells like your problem is with the parameters you are giving the GetRows() method. I'm not familiar with the options, since I always use myArray = RS.GetRows() and leave it at that.
-
Sorry, I thought you were using VB, not VBScript. In VBScript all variables are variants by default. So try:
Code:
Dim arData, arLabels
arData = Rs.GetRows()
arLabels -= Rs.GetRows()