Re: BOOLEAN VBA FUNCTION !!!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Jay Dean

This should do what you are looking for:

Public Function MyFun(String1 As String, String2 As String) As Boolean
Dim arr1 As Variant
Dim arr2 As Variant
If String1 = "" Or String2 = "" Then
Exit Function
End If
If InStr(1, String1, ",") Then
arr1 = Split(String1, ",")
Else
ReDim arr1(0)
arr1(0) = String1
End If

If InStr(1, String2, ",") Then
arr2 = Split(String2, ",")
Else
ReDim arr2(0)
arr2(0) = String2
End If

For c = LBound(arr2) To UBound(arr2)
For r = LBound(arr1) To UBound(arr1)
If arr2(c) = arr1(r) Then
Token = Token + 1
Exit For
End If
Next
Next
If Token = UBound(arr2) + 1 Then
MyFun = True
End If
End Function

Regards,
Per

"jay dean" <fresh1700@xxxxxxxxx> skrev i meddelelsen news:u2B2dKFCKHA.3800@xxxxxxxxxxxxxxxxxxxxxxx
Hi -

I'm looking for a Boolean VBA function, MyFun, that takes in 2 input
strings, String1 and String2, like MyFun(String1,String2). Here are the
specs:

(1) If ALL the tokens in String2 are also tokens of String1, then MyFun
will output to "True", otherwise, it should return "False"

(2) Also, if either String1 or String2 is empty "", then MyFun will
return "False"

(3) The tokens in both input strings are delimited by "," except when
there is only one token contained in any input.

Example:
MyFun("YH,L,GT,W,B,Q","B,GT,YH") should return "True"

MyFun("H,C,KK,V","") should return "False"

MyFun("AY,DC,GJ,U","AY,U,Z") should return "False"

I would appreciate any assistance!
Thank you.
Jay Dean

*** Sent via Developersdex http://www.developersdex.com ***

.



Relevant Pages

  • strtok question
    ... The splitString(string1); works as expected, 3 tokens are found. ... The splitString(string2); does not work as I expected. ... Why does it not see the empty field for lineToken2? ...
    (comp.lang.c)
  • Re: strtok question
    ... The splitString(string2); does not work as I expected. ... Because that's not how strtok() works. ... A sequence of two or more contiguous delimiter characters in the ... the tokens returned by strtokare always non-empty ...
    (comp.lang.c)