我正在检查名称文本框是否以 Mr. Mrs. Ms. 等开头。
我创建了一个函数,但无法比较多个字符串。
这是我的代码。
'Checking whether name is starts with Mr./Mrs./Ms./Dr. or not
If Not FindString(LCase(Me.gname.Value), LCase("Mr")) Then
MsgBox "Consumer Name Starts with Mr./Mrs./Ms./Dr. Check Consumer Name"
Cancel = True
Exit Sub
End If
'Here is the Find String function i created
Function FindString(strCheck As String, strFind As String) As Boolean
Dim intPos As Integer
intPos = 0
intPos = InStr(strCheck, strFind)
FindString = intPos > 0
End Function
将字符串作为由分隔符分隔的字符串组传递,例如:-
FindString(LCase(Me.gname.Value), LCase("Mr;Mrs;Ms;Dr"))
现在将它们分开并使用循环进行比较。
Arr = Split(strFind,";")
Flag = 0
For Each str in Arr
If InStr(strCheck, str) > 0 Then
Flag = 1
End If
Next
If Flag = 1 Then
FindString = True
Else
FindString = False
End If
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)