From: Alan on 7 Feb 2009 23:48 I get Run-time error 5018 ("Application-defined or object-defined error") on the following line of code: If (oRegEx.test(sInputString) = True) Then when I try to test a string with a regular expression. Any idea why and/or what this error means? Here is the function: Function TextFound(sInputString As String) As String Dim oRegEx As Object Dim mcMatchedStrColl As MatchCollection, mMatch As Match Set oRegEx = New RegExp With oRegEx .Pattern = "Word:?*Definition:" .IgnoreCase = True .MultiLine = True 'Debug.Print sInputString If (.test(sInputString) = True) Then Set mcMatchedStrColl = .Execute(sInputString) For Each mMatch In mcMatchedStrColl TextFound = mMatch.Value Set oRegEx = Nothing Exit Function Next Else TextFound = "" End If End With Set oRegEx = Nothing End Function and here is how I call it: Dim aString As String . . . aString = "Word: annoy. Definition:" MsgBox ("Text found is: " & TextFound(aString )) End Sub Thank you in advance for any help on this. --- Alan
From: mayayana on 9 Feb 2009 11:05 You seem to be in the wrong group with both of your questions. This group is for VB. Your first question is VBA. That's for MS Office? VB and VBA and VBScript are 3 separate things. (And then there's VB.Net, which gets into a whole other kettle of fish.) Maybe something like this would be good? microsoft.public.office.developer.vba Looking at the msnews server listings there seem to be a lot of Office-related groups. But this isn't one of them. The RegExp is generally a scripting tool. Again, it's possible someone here can help you but you're really in the wrong group. If you don't get your answer about RegExp in an Office group try: microsoft.public.scripting.vbscript > I get Run-time error 5018 ("Application-defined or object-defined > error") on the following line of code: > > If (oRegEx.test(sInputString) = True) Then > > when I try to test a string with a regular expression. > > Any idea why and/or what this error means? > > Here is the function: > > Function TextFound(sInputString As String) As String > Dim oRegEx As Object > Dim mcMatchedStrColl As MatchCollection, mMatch As Match > Set oRegEx = New RegExp > With oRegEx > .Pattern = "Word:?*Definition:" > .IgnoreCase = True > .MultiLine = True > 'Debug.Print sInputString > If (.test(sInputString) = True) Then > Set mcMatchedStrColl = .Execute(sInputString) > For Each mMatch In mcMatchedStrColl > TextFound = mMatch.Value > Set oRegEx = Nothing > Exit Function > Next > Else > TextFound = "" > End If > End With > Set oRegEx = Nothing > End Function > > and here is how I call it: > > Dim aString As String > . . . > aString = "Word: annoy. Definition:" > MsgBox ("Text found is: " & TextFound(aString )) > End Sub > > Thank you in advance for any help on this. --- Alan
From: Alan on 9 Feb 2009 19:33 Thank you.
|
Pages: 1 Prev: Printing ALL content in large PictureBox which has scrollbars Next: Listbox vbTab use |