Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array returning too short

Status
Not open for further replies.

trix13

Programmer
Feb 20, 2006
30
US
I have an array I create from data from my SQL database. I've already checked the procedures within SQL and they work. In fact, when I debug my recordcount is correct - 84. However, when I run my page that displays the array I only receive 5 records. I can get the first five, last five, I even got the 5 in the middle. There are 5 elements (name, city, etc) and those appear correctly, but the length of the array is only appearing as 5 when I KNOW it's 84. Please look at the following code...Any suggestion would be appreciated...

Code:
Public Function GetClubsFromZip(zip As Integer) As Variant
Dim csql$, i%, x%, count%
Dim myarray
ReDim myarray(4, 0)

OpenSQLConnection

Dim rs1 As New ADODB.Recordset
Set rs1 = CreateObject("ADODB.Recordset")

csql$ = "GetZipCodesWithin50Miles " & zip


With rs1
    .ActiveConnection = rdoConn
    .CursorLocation = adUseClient
    .LockType = adLockReadOnly
    .CursorType = adOpenForwardOnly
    .Open (csql$)
End With

If Not rs1.EOF Then
    While rs1.EOF = False
        
        ReDim Preserve myarray(4, rs1.RecordCount)
        
        For x = 0 To rs1.RecordCount - 1
        
            myarray(0, x) = rs1(0)
            myarray(1, x) = rs1(1)
            myarray(2, x) = rs1(2)
            myarray(3, x) = rs1(3)
            myarray(4, x) = rs1(4)
                
            rs1.MoveNext
        
        Next x
        
        myarray(0, count) = TakeoutdoubleQuote(CStr(myarray(0, count)))
        

      
    Wend

Else
    For i = 0 To 4
    
        myarray(i, 0) = "NONE"
    Next i

End If
rs1.Close
Set rs1 = Nothing
rdoConn.Close
Set rdoConn = Nothing
GetClubsFromZip = myarray
End Function

Now I have recently posted about the finding zip code aspect of this in an effort to create the SQL in VB. At the moment I just have to make it work the way I originally had it. UNFORTUNATELY this nitwit deleted my function instead of commenting it out which is why I seem to be missing something simple now. Please help the brain dead. :)


-trix
"Wiggle your big toe.
 
It looks like you have a count variable, that you declare, and use, but never change the value of.

Given your current method, it looks like you need to add: Count = Count + 1 within your loop.


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
You know guys I feel so stupid. The error was not here in this code, but on my actual web page where I drew in the array. I was using ubound(clubs) which was 5, the 5 elements right? I was supposed to have ubound(clubs,2), which accessed my 84 records. I apologize for the wasted post. My error was on another page altogether. Sorry!!!

-trix
"Wiggle your big toe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top