View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
keiji kounoike keiji kounoike is offline
external usenet poster
 
Posts: 199
Default BOOLEAN VBA FUNCTION !!!

I don't know whether or not this one is what you want, because i don't
know if i understand your criteria correctly.
MyFunc below can deal arguments with both array and string. I used
Rick's MyFun in MyFunc because it was easy to write the code. Of course,
It's better to write equivalent code to Myfunc in MyFunc for the time of
processing.

Function MyFunc(s1, s2) As Boolean
Dim i As Long, j As Long
Dim tmp As Boolean
If (VarType(s1) = vbArray + vbVariant Or _
VarType(s1) = vbArray + vbString) And _
(VarType(s2) = vbArray + vbVariant Or _
VarType(s2) = vbArray + vbString) Then
For i = 0 To UBound(s2)
For j = 0 To UBound(s1)
If MyFun(s1(j), s2(i)) Then
tmp = True
Exit For
End If
Next
If j UBound(s2) Then
tmp = False
Exit For
End If
Next
ElseIf (VarType(s1) < vbArray + vbVariant And _
VarType(s1) < vbArray + vbString) Or _
(VarType(s2) < vbArray + vbVariant And _
VarType(s2) < vbArray + vbString) Then
tmp = False
Else
tmp = MyFun(s1, s2)
End If
MyFunc = tmp
End Function

'Below is the Rick's code

Function MyFun(ByVal s1 As String, ByVal s2 As String) As Boolean
Dim i As Long, S1FixedUp As String, sTokens2() As String
S1FixedUp = "," & Replace(s1, " ", "") & ","
sTokens2 = Split(Replace(s2, " ", ""), ",")
For i = 0 To UBound(sTokens2)
If InStr(S1FixedUp, "," & sTokens2(i) & ",") = 0 Then Exit Function
Next
If i 0 And i = UBound(sTokens2) + 1 Then MyFun = True
End Function

Keiji

jay dean wrote:
Rick, Keiji, Ron, and Per -

I would like to 'ramp' MyFun up one dimension if possible. I'd like to
build on MyFun another Boolean function, MyFun2 that takes in two 1D
String arrays, String1() and String2(), like MyFun2(String1(),
String2()) as Boolean. Here are the specs:

(1)MyFun2 has same specs as MyFun, except that MyFun2 takes in two 1D
String arrays, instead of two Strings.

(2)If ALL the indexes of String2() are also indexes of String1(), then
MyFun2 will return "True", otherwise, it returns "False"

Example:

String1=("AY,F,VV,M","K,OP,CG,FF","E,Q,S,2H")
String2=("S,E","Q,2H","M,AY","VV,F")
MyFun2(String1(),String2()) should return "True"

String1=("BB,U,W","Q,AA,Z","XX,T,SS")
String2=("U,W,BB","W,AA,U","BB,SS,XX")
MyFun2(String1(),String2()) should return "False"

Thanks
Jay Dean




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