Dynamic array and Nested For i= HELP PLEASE!!

Results 1 to 2 of 2

Thread: Dynamic array and Nested For i= HELP PLEASE!!

  1. #1
    JB Guest

    Default Dynamic array and Nested For i= HELP PLEASE!!

    Hi,<BR><BR>I have 2 tables. One set up for Categories and the other for Subcategories.<BR><BR>I am trying to load both the Categories and Sub Categories onto Arrays and I am having trouble. The SubCategory array should reference the Category Array.<BR><BR>I hope the code below will be self explanitory.<BR><BR>I am getting a "Subscript out of range" Error on the line that reads....<BR><BR>Redim Preserve strSubCatTitle(i, e)<BR><BR>Any Help will be appreciated.<BR><BR>Thanks,<BR>JB<BR><BR>&#060;!-- CODE START -- &#062;<BR><BR>Dim rs, rsSQL, intRecCount, i, strCatTitle(), intCatID<BR>Dim rsSub, rsSubSQL, intSubRecCount, strSubCatTitle(), e<BR><BR><BR> Set strConn = Server.CreateObject("ADODB.Connection")<BR> strConn.Open strConnString<BR><BR> Set rs = Server.CreateObject("ADODB.Recordset")<BR> rsSQL = "SELECT * FROM EC_Categories WHERE CatActive LIKE &#039;Yes&#039; ORDER by CatDisplayOrder"<BR> rs.Open rsSQL, strConnString, adOpenStatic, adLockOptimistic, adCmdText<BR><BR> Set rsSub = Server.CreateObject("ADODB.Recordset")<BR> rsSubSQL = "SELECT * FROM EC_SubCategories WHERE SubCatActive LIKE &#039;Yes&#039;"<BR> rsSub.Open rsSubSQL, strConnString, adOpenStatic, adLockOptimistic, adCmdText<BR><BR> intRecCount = rs.RecordCount<BR><BR> Redim strCatTitle(0)<BR><BR> &#039;## BEGIN LOOP<BR> For i = 0 To intRecCount - 1<BR><BR> Redim Preserve strCatTitle(i)<BR> strCatTitle(i) = rs("CatTitle")<BR> intCatID = rs("CatID")<BR><BR> rsSub.Filter = "CatNo = &#039;"&intCatID&"&#039;"<BR> intSubRecCount = rsSub.RecordCount<BR><BR> Redim strSubCatTitle(0,0)<BR> <BR> &#039;## BEGIN SUB LOOP<BR> For e = 0 To intSubRecCount - 1<BR> Redim Preserve strSubCatTitle(i, e)<BR> <BR> strSubCatTitle(i, e) = rsSub("SubCatTitle")<BR> Response.Write(strSubCatTitle(i, e))<BR> rsSub.MoveNext<BR> <BR> Next<BR> rsSub.Filter = adFilterNone<BR><BR> rs.MoveNext<BR> Next<BR><BR> rsSub.Close<BR> Set rsSub = Nothing<BR>rs.Close<BR>Set rs = Nothing<BR>strConn.Close<BR>Set strConn = Nothing<BR><BR>&#060;!-- CODE END --&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: Dynamic array and Nested For i= HELP PLEASE!!

    Redim strSubCatTitle(0,0)<BR><BR>This is inside your first loop. It will reset your array. Try using Redim preserve inside the secind loop before you movenext and use Redim Preserve strSubCatTitle(i,e)<BR><BR>

Posting Permissions

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