Question : VB Script help needed !

<html>
      <head>
            <script language="vbscript">

            Sub MethExecute()

                  Dim objRegEx, objMatch, strString, strDisplayMsg
   
                     Set objRegEx = CreateObject("VBScript.RegExp")
                  objRegEx.Pattern = "bear"
                  objRegEx.Global = True
                  objRegEx.IgnoreCase = True            

                  strString = "Once upon a time there were three little Bears. There was mama Bear, papa Bear and baby bear"

                  strDisplayMsg = ""

                  While (objMatch = objRegEx.Execute(strString))
                        strDisplayMsg = strDisplayMsg & " An instance of " + objMatch(0) & " found at position " & CStr(CInt(objMatch.Index) + 1) & VbCrlf
                  Wend

                  MsgBox(strDisplayMsg)      
                  
            End Sub

            </script>

      </head>
      
      <body>

            <script>

                  Call MethExecute()

            </script>
      
      </body>

</html>

The above code is giving an error. Can you please fix the above program and make it work ?

Thanks

Answer : VB Script help needed !

Try this.

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Sub MethExecute()
 
   Dim objRegEx, objMatch, strString, strDisplayMsg
 
   Set objRegEx = CreateObject("VBScript.RegExp")
   objRegEx.Pattern = "bear"
   objRegEx.Global = True
   objRegEx.IgnoreCase = True            
 
   strString = "Once upon a time there were three little Bears. There was mama Bear, papa Bear and baby bear"
 
   strDisplayMsg = ""
 
   For Each objMatch in objRegEx.Execute(strString)
      strDisplayMsg = strDisplayMsg & " An instance of " + objMatch.Value & " found at position " & CStr(CInt(objMatch.FirstIndex) + 1) & VbCrlf
   Next
 
   MsgBox(strDisplayMsg)      
   
End Sub
Random Solutions  
 
programming4us programming4us