[AccessD] Find characters in one stringthatareinanother:w asRE: Treat string as array

Max Wanadoo max.wanadoo at gmail.com
Tue Mar 25 12:02:49 CDT 2008


Yes, and it can be made even shorter if you didn't want the actual count or
the positioning of the char.
Then just throw it the test you want, eg:  
Eg: if (RegExpTest("\W", strPwd))=0 then "Invalid Pwd" ' \W for a non-word
char and your done!
Max

 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Tuesday, March 25, 2008 4:28 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Find characters in one stringthatareinanother:w asRE:
Treat string as array

Max,

Actually I do appreciate the example.  I have always wanted to learn RegEx
just never had the time.  

For this application it is rather like aiming an ICBM at the old fly.  It
sure is short though once you have RegExpTest() written. 


John W. Colby
Colby Consulting
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo
Sent: Tuesday, March 25, 2008 12:15 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Find characters in one string thatareinanother:w
asRE: Treat string as array

You might not want this then,  but it is an alternative.

Max

Function tryRegEx()
  Dim lngResult As Long, strPwd As String
  strPwd = "~12+#xyz"
  lngResult = (RegExpTest("\W", strPwd))  ' uppercase W (   Matches any
nonword character)
  If lngResult > 0 Then MsgBox "Test 1: " & lngResult & " matched - as
non-alph"
  lngResult = (RegExpTest("\w", strPwd))   ' lowecase w ( Matches any word
character))
  If lngResult > 0 Then MsgBox "Test 2: " & lngResult & " matched as alpha"
  lngResult = (RegExpTest("\d", strPwd))    ' lowercase d (  Matches any
decimal digit.)
  If lngResult > 0 Then MsgBox "Test 3: " & lngResult & " matched - as
decimal"
End Function

Function RegExpTest(patrn, strng) As Long ' Set reference to Microsoft
vbscript regular expressions 5.5 ' Cheat Sheet available at
http://regexlib.com/CheatSheet.aspx
  Dim RegEx As New VBScript_RegExp_55.RegExp
  Dim Match, Matches, RetStr  ' Create variable.
  Set RegEx = New RegExp   ' Create a regular expression.
  RegEx.Pattern = patrn   ' Set pattern.
  RegEx.IgnoreCase = True   ' Set case insensitivity.
  RegEx.Global = True   ' Set global applicability.
  Set Matches = RegEx.Execute(strng)   ' Execute search.
  RegExpTest = 0
  For Each Match In Matches   ' Iterate Matches collection.
    RetStr = RetStr & "Match found at position "
    RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
    RetStr = RetStr & Match.Value & "'." & vbCrLf
    RegExpTest = RegExpTest + 1
  Next
End Function
  

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Tuesday, March 25, 2008 3:55 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Find characters in one string that areinanother:w
asRE: Treat string as array

Just an update, I have integrated Gustav's solution in my LWS and now have
password rule checking in place.

John W. Colby
Colby Consulting
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Heenan, Lambert
Sent: Tuesday, March 25, 2008 11:15 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Find characters in one string that are inanother:w
asRE: Treat string as array

But John, didn't you see Gustav's response very early on in the thread
suggesting you use StrConv? Armed with that clue your dream of using a
simple for next loop is easily achieved...

Function StringArray(str As String) As Variant Dim byArray() As Byte
    byArray = StrConv(str, vbFromUnicode)
    StringArray = byArray
End Function

Sub PlayWithStringArray(str As String)
Dim byArray() As Byte
Dim c As Variant
    byArray = StringArray(str)
    For Each c In byArray()
        Debug.Print c; " "; Chr(c);
    Next c
    Debug.Print vbCrLf; str
End Sub

You're on the money though about the number of answers that seemed not to be
connected with the question! :-)

Lambert

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Tuesday, March 25, 2008 11:01 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Find characters in one string that are in
another:wasRE: Treat string as array


LOL.  

Turn a string into an array.  Turn a string into an ARRAY.  TURN A STRING
INTO AN ARRAY.  

That was my question.  Why I want to do it is irrelevant.

And yea, Regex probably would work, but I did not have time to spend a week
learning a useful but EXTREMELY arcane syntax to solve a 5 minute problem.
In fact I didn't have time to answer 25 suggestions having nothing to do
with TURNING A STRING INTO AN ARRAY. 

Sigh.

;-)

John W. Colby
Colby Consulting
www.ColbyConsulting.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list