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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subscript out of range on a dynamic array 1

Status
Not open for further replies.

theocraticmind

Programmer
Apr 19, 2002
318
CA
i dim an array, and use split to fill it right away. i don't give it a size because i don't know what size it will need. but i still get subscript out of range. here is the code:
Code:
Function quoteFilter(string1)
 dim aray()
 dim new_string
 aray() = split(string1,chr(34))
 for i = 0 to 100
  if aray(i) = "" or aray(i) = null then
   i = 101
   next
  end if
  new_string = new_string & aray(i) & "-double-quote-"
 next
 quoteFilter = new_string
End Function
 
you set i=101 then do a lookup with new_string = new_string & array(i) ....

How do you know that the array has 101 elements. I think the problem is in your loop. You need to find the number of elements, not use a hard coded 100 Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
if i set i to 101, it leaves the loop before it gets to new_string = new_string & array(i). notice "next" in the if statment. then once i = 101, the loop will stop due to i's large value. but that dosen't even matter because the error is on the line that says: aray() = split(string1,chr(34))
 
A Next ends the For You can NOT have two Nexts. Perhaps you wanted Exit For...BUT I would still use UBound.
Function quoteFilter(string1)
dim aray()
dim new_string
aray() = split(string1,chr(34))
''''for i = 0 to 100
for i = 0 to Ubound(aray)
if aray(i) = "" or aray(i) = null then ''''i = 101
''''next
exit for
end if
new_string = new_string & aray(i) & "-double-quote-"
next
quoteFilter = new_string
End Function
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Ubound returns the upper bound of the array. It is fundamental to Basic. If you want to write VBscript, it would help if you knew the fundamentals of VBScript.
Start at the following link and read it all.
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
ya, honestly i don't know a whole lot about VBscript. i took a class on VB, and so far it has been enough. well...that, and DevGuru.
 
ok, new function:

Function quoteFilter(string1)
dim aray()
dim new_string
aray() = split(string1,chr(34)) ''''this line
for i = 0 to Ubound(aray)
new_string = new_string & aray(i) & "-double-quote-"
next
quoteFilter = new_string
End Function

still have the same subscript out of range error...
 
wow, that was all a large wast of time. thanks for letting me know befoer i wasted more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top