Subscript out of range error

Results 1 to 6 of 6

Thread: Subscript out of range error

  1. #1
    Adrian Guest

    Default Subscript out of range error

    Could someone tell me why Dim A(10) works, but Dim A() has "subscript out of range" runtime error on line 6?<BR>&#060;%<BR>Dim A(10), i<BR>i=0<BR>do until i=10<BR> A(i) = i &#039&#060;&#060; #6<BR> i=i+1<BR>loop <BR>do until i=0<BR> response.write (i) <BR> i=i-1<BR>loop<BR>%&#062;

  2. #2
    Nathen Grass Guest

    Default RE: Subscript out of range error

    You need to redimension (ReDim) a dynamic array before you make a reference to it.<BR><BR>i.e.<BR><BR>Dim A(), i<BR><BR>ReDim A(10)<BR><BR>i=0<BR>...<BR><BR><BR>

  3. #3
    Adrian Guest

    Default RE: Subscript out of range error

    I take it then, having just Dim A() is illegal? It has to have the dimensions?<BR><BR>So then could you tell me how to count the number of folders and put their names in the array (dynamically) ?<BR>Thanks

  4. #4
    Join Date
    Dec 1969
    Posts
    572

    Default RE: Subscript out of range error

    Your i can go only up to 9, or you have to dim your array A(11).


  5. #5
    Adrian Guest

    Default this works

    This works. Is there a more elegant way???<BR>&#060;%<BR>Dim Path, fso, folder, name, Item, A(), i, upper<BR>Path = "./"<BR>Set fso = CreateObject("Scripting.FileSystemObject")<BR>Set folder = fso.GetFolder(server.mappath(path))<BR>name = folder.name<BR><BR>i=0<BR>For Each item In folder.subfolders <BR>ReDim preserve A(i)<BR>A(i) = item.name<BR>i=i+1<BR>Next<BR>upper = Ubound(A)<BR>i = 0<BR>do until i = upper + 1<BR> response.write"&#060;A HREF=" & A(i) & "&#062;" & A(i) & "&#060;/a&#062;<BR>"<BR> i= i+1<BR>loop%&#062; <BR>

  6. #6
    John Weeflaar Guest

    Default RE: this works

    Actually, You don&#039t need an array. <BR>For Each item In folder.subfolders <BR>&#039 On one line<BR>response.write "&#060;a HREF=" & item.name & "&#062;" & item.name & "&#060;/a&#062;"<BR>Next

Posting Permissions

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