Link to home
Start Free TrialLog in
Avatar of ckawebcreation
ckawebcreationFlag for United States of America

asked on

Microsoft VBScript runtime (0x800A0009) Subscript out of range: 'i'

i am using a dreamweaver exchange plugin to create a forum, it works fine apart from when the user clicks to add more than 2 smiley's on the same message,the following error appears??

Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: 'i'
/vbforum/Library/vbslib.asp, line 70

This is the code for lines 68 - 72

 i = 0
    For Each Match in Matches
      retStr(i) = Match.value
      i = i+1
    Next

Any ideas?  I csan post more code if required, cheers..
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Looks to me like i eventually grew to be larger than the upper bound on the array retStr.  That is the
typical cause for a subscript out of range error...
Avatar of ckawebcreation

ASKER

hi matthewspatrick,

how do I find the upperbound on the array retStr?

Cheers
ckawebcreation,

Perhaps you should post the rest of the code :)

Regards,

Patrick
hi matthewspatrick,

this is the rest of the code, it is actually a variable page for the site, the error in question is when a preview of the main message is being requested. i do not know if you need that code as well?

<%
Dim theoffset
theoffset = ""
If (cStr(Session("offset")) <> "") Then
  theoffset = "&offset=" & cStr(Session("offset"))
End If
%>
<%
Dim theoffset2
theoffset2 = ""
If (cStr(Request("offset")) <> "") Then
  theoffset2 = "&offset=" & cStr(Request("offset"))
End If
%>
<%
Dim search1
search1 = ""
If (cStr(Request("Str")) <> "") Then
  search1 = "Str=" & Server.URLEncode(cStr(Request("Str"))) & "&"
End If
%>
<%
Dim theorder
theorder = ""
If (cStr(Request("order")) <> "") Then
  theorder = "&order=" & cStr(Request("order")) & "&verse=" & cStr(Request("verse"))
End If
%>
<% ' get date and time
theday = Day(Now())
themonth = Month(Now())
theyear = Year(Now())
h = Hour(Now())
m = Minute(Now())
s = Second(Now())
If (themonth = 1) Then lmonth = "Jan"
If (themonth = 2) Then lmonth = "Feb"
If (themonth = 3) Then lmonth = "Mar"
If (themonth = 4) Then lmonth = "Apr"
If (themonth = 5) Then lmonth = "May"
If (themonth = 6) Then lmonth = "Jun"
If (themonth = 7) Then lmonth = "Jul"
If (themonth = 8) Then lmonth = "Aug"
If (themonth = 9) Then lmonth = "Sep"
If (themonth = 10) Then lmonth = "Oct"
If (themonth = 11) Then lmonth = "Nov"
If (themonth = 12) Then lmonth = "Dec"
lDate = lmonth & " " & theday & ", " & theyear
If (themonth < 10) Then themonth = "0" & themonth
If (theday < 10) Then theday = "0" & theday
If (m < 10) Then m = "0" & m
If (s < 10) Then s = "0" & s
nDate = theday & "/" & themonth & "/" & theyear
rDate = themonth & "/" & theday & "/" & theyear
ntime = h & "." & m & "." & s
%>
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Function StringMatch(theStr, thePattern)
    Dim objRegEx, Match, Matches, i, retStr(1)
    Set objRegEx = New RegExp
 
    objRegEx.Global = True
    objRegEx.IgnoreCase = True
    objRegEx.Pattern = thePattern
 
    Set Matches = objRegEx.Execute(theStr)
 
    i = 0
    For Each Match in Matches
      retStr(i) = Match.value
      i = i+1
    Next

    StringMatch = retStr
End Function

Function reformat(text)
  var1 = text
  match = StringMatch(var1, "<" & "script[^>]*?" & ">" & "[\W\w]*" & "<" & "\/script" & ">")
  For i=0 To Ubound(match)
    var1 = Replace(var1, match(i), "")
  Next
  var2 = Replace(var1, "<", "&" & "lt;")
  var3 = Replace(var2, ">", "&" & "gt;")
  match = StringMatch(var3, "(\s|^)www\.[^\[\*\s]+\b")
  For i=0 To Ubound(match)
    url = Replace(match(i), " ", "")
    newStr = "<a href='http://" & LCase(url) & "' target='_blank'>" & url & "</a>"
    var3 = Replace(var3, url, newStr)
  Next
  match = StringMatch(var3, "(\s|^)http:\/\/[^\[\*\s]+\b")
  For i=0 To Ubound(match)
    url = Replace(match(i), " ", "")
    url2 = Replace(url, "http://", "")
    newStr = "<a href='http://" & LCase(url2) & "' target='_blank'>" & url2 & "</a>"
    var3 = Replace(var3, url, newStr)
  Next
  match = StringMatch(var3, "\b[^\]\s]+@[^\[\*\s]+\b")
  For i=0 To Ubound(match)
    addr = Replace(match(i), " ", "")
    newStr = "<a href='mailto:" & addr & "'>" & addr & "</a>"
    var3 = Replace(var3, addr, newStr)
  Next
  match = StringMatch(var3, "\*¦(\w+)¦\*")
  For i=0 To Ubound(match)
    url = match(i)
    name = Replace(Replace(url, "¦", ""), "*", "")
    newStr = "<img src='../smilies/" & name & ".gif'>"
    var3 = Replace(var3, url, newStr)
  Next
  newStr = "<table width=""94%"" cellspacing=""0"" cellpadding=""0"" border=""0"" align=""center""><tr><td><font face=""Verdana"" size=""1""><b>&nbsp;"
  var3 = Replace(var3, "[call]", newStr)
  newStr = "</b></font></td></tr></table>"
  var3 = Replace(var3, "[/call]", newStr)
  newStr = "<table width=""94%"" cellspacing=""0"" cellpadding=""8"" border=""1"" align=""center""><tr><td bgcolor=""#FFFFFF""><font size=""2""><i>"
  var3 = Replace(var3, "[quote]", newStr)
  newStr = "</i></font></td></tr></table>"
  var3 = Replace(var3, "[/quote]", newStr)
  var4 = var3 & " "
  varText = Replace(var4, vbCr, "<br>")
  reformat = varText
End Function

Function ceil(num)
  theNum = int(num)
  If (num > theNum) Then theNum = theNum+1
  ceil = theNum
End Function
</SCRIPT>
ckawebcreation said:
>>    Dim objRegEx, Match, Matches, i, retStr(1)

Based on that line, the upper bound of the array is 1 (and the lower bound is zero).  Thus, on this line:

      retStr(i) = Match.value

If i > 1, you get a subscript out of range.
soif i change the 1 value to 20 it will give me a lot more options?
Try something like this to make it dynamic:



Function StringMatch(theStr, thePattern)
    Dim objRegEx, Match, Matches, i, retStr()
    Set objRegEx = New RegExp
 
    objRegEx.Global = True
    objRegEx.IgnoreCase = True
    objRegEx.Pattern = thePattern
 
    Set Matches = objRegEx.Execute(theStr)
 ReDim retStr(0 To Matches.Count - 1)
    i = 0
    For Each Match in Matches
      retStr(i) = Match.value
      i = i+1
    Next

    StringMatch = retStr
End Function
it gives me this error

Error Type:
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/vbforum/Library/vbslib.asp, line 67, column 15
ReDim retStr(0 To Matches.Count - 1)
--------------^
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Magic!!!!!  thanksforthe help..