Results 1 to 5 of 5

Thread: Problem w/ Arrays

  1. #1

    Thread Starter
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016

    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

  2. #2
    CMangano
    Guest
    Try doing:

    Code:
    Dim arData As Variant
    Dim arLabels As Variant
    Then when you pass GetRows into them, they will become arrays.

  3. #3

    Thread Starter
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    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

  4. #4
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    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.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  5. #5
    CMangano
    Guest
    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()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width