troubleshooting Question

vba code Array Searching..matching : error 9 subscript out of range

Avatar of Fordraiders
FordraidersFlag for United States of America asked on
Microsoft Access
5 Comments2 Solutions459 ViewsLast Modified:
Access 2003:
vba


I'am trying to find 3's or triplet matching inside a string array..

If the three tokens exist consecutively then they get good points..

example:
(cArr)Array strings   "ENGINE OIL MP3"

iF THIS PHRASE EXIST INSIDE THE BELOW STRING it gets better points..


Sg =    MOTORCRAFT ENGINE OIL MP3 BEATS THE BEST



 For x = lb To ub - 1
       ' Loop 88
  If InStr(sG, " " & cArr(x) & " " & cArr(x + 1) & " " & cArr(x + 2) & " ") > 0 Then
       If InStr(didfindstring, " " & cArr(x) & " " & cArr(x + 1) & " " & cArr(x + 2) & " ") = 0 Then
         didfindstring = didfindstring & "| " & cArr(x) & " " & cArr(x + 1) & " " & cArr(x + 2) & " |"
          score = score + 100
           wdFound = wdFound & "," & "L88B100," & cArr(x) & " " & cArr(x + 1) & " " & cArr(x + 2)
       End If
 End If
               
Next

Getting error on this line
If InStr(sG, " " & cArr(x) & " " & cArr(x + 1) & " " & cArr(x + 2) & " ") > 0 Then    '  <---- error here
because I may be at the end of the "Sg" string and three tokens may not exist.
error number 9 substript out of range because   cArr(x + 2)   may not exist because I'am at the end of the string.

Thanks
fordraiders
ASKER CERTIFIED SOLUTION
Arthur_Wood

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros