Normally this function returns only the alphanumerics...
Takes a string like "AS456^(SK)-4"
and returns "AS4564"
Recently it started doing this:
Takes a string like "AS456^(SK)-4"
and returns "^()-"
I fixed that by taking the passed string as a value (the original code had nothing there)
Then a few days ago, what caused me to think about the details of this code is that one report needed to preserve the dash and underscore in some of the strings... so I altered the pattern expression....
It dawned on me... why does that work?
The pattern is inside the the IF...THEN structure... I'm using late binding so the Object RegEx should always be "Nothing;" thus the pattern and the object should never be read... and yet, this works!?
I've stepped thru the code a 100 times and the lines inside the IF...THEN structure never executes.
If you take the pattern as it is in the code below:
"AS123@#$_345-Az"
will return
"AS123_345-Az"
If you alter the code to my normal pattern of
Expand|Select|Wrap|Line Numbers
- .Pattern = "[^a-zA-Z0-9]"
"AS123@#$_345-Az"
will return
"AS123345Az"
and yet the line is never executed.
(I'm using late binding here; so no library references to the regular expressions so that I don't have to deal with seting the reference on all of the lab-PCs)
Expand|Select|Wrap|Line Numbers
- Function RemChrs(ByVal s As String) As String
- Static RegEx As Object
- If RegEx Is Nothing Then
- Set RegEx = CreateObject("VBScript.RegExp")
- With RegEx
- .Global = True
- .Pattern = "[^a-zA-Z0-9_\-]"
- End With
- End If
- RemChrs = RegEx.Replace(s, "")
- End Function
Dazed and confussed (@_@)