Error::Subscript out of range: 'name'

Results 1 to 3 of 3

Thread: Error::Subscript out of range: 'name'

  1. #1
    Bourke IV Guest

    Default Error::Subscript out of range: 'name'

    I cut this out of my code and started a new ASP page to test, I still cant get the GetRows to work. <BR>If you Cut off everything when the For Each loop starts it returns 1, I have two String rows in that database in that field.<BR>"Menu" and "Other", but I want to be able to change this whenever.<BR><BR>See the bottom::--&#062;<BR><BR>CODE START&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&<BR>&#060;%<BR> &#039;myConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:webwrit-studioswritwritData.mdb;"<BR>myConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:InetpubwwwrootWritwritData.mdb;"<BR>&#039 ;-------------------------------------------------------------------------------------------<BR>Set rsFind = Server.CreateObject("ADODB.Recordset")<BR> rsFind.Open "SELECT DISTINCT menuGroup FROM Menu", myConn<BR> name=rsFind.GetRows()<BR> rsFind.Close<BR>Set rsFind = Nothing<BR><BR>iArraySize = (UBound(name) - LBound(name)) + 1<BR>Response.Write iArraySize<BR>i=0<BR>For Each i in name<BR>Response.Write name(i)<BR>i=i+1<BR>Next<BR>&#039;------------------------------------------------------------------------------------------<BR>%&#062;<BR><BR>--&#062;<BR>When I use GetRows and place it in a array, does it make a set for each field? say I have 5 fields in that one database table, but I use SQL to take it down to one field, will the array still make empty sets of the other fields?<BR><BR>like this<BR>name(0,0,0,1,0) that being 5 sets.

  2. #2
    Join Date
    Dec 1969

    Default TWO dimensional array!

    GetRows returns a TWO dimensional array, *NOT* a one dimensional!<BR><BR>So if you would like to see ALL the data in the array:<BR><BR>&#060;%<BR>..<BR>name = rsFind.GetRows()<BR>rsFind.Close<BR>Set rsFind = Nothing<BR><BR>For row = 0 To UBound( name, 2 ) &#039; LBound *always* 0...and we need SECOND dim<BR>&nbsp; &nbsp; For col = 0 To UBound( name, 1 ) &#039; columns are first dim!<BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Write "Record " & row & ", field " & col & " = " & name(col,row) & "&lt;BR&#062;"<BR>&nbsp; &nbsp; Next<BR>Next<BR>...<BR>%&#062;<BR><BR>Note that even if you ask for only one field per record, you *still* get a 2-D array...just that then UBOUND(arrayName,2) will be zero. Actually simplifies things, since your code is always the same!<BR><BR><BR><BR>

  3. #3
    Bourke IV Guest

    Default Great tip, thanks a ton (notext inside)


Posting Permissions

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