嗨,到目前为止,我在文本框中找到一个字符串时遇到了这个问题,这是我只检测到逗号字符,现在我输入 23pm,24,25am 我将如何使用此代码执行此操作,或者任何人都可以给我简单的代码?
Dim tdates() As String
Dim numberOfDates, xcount As Integer
tdates = Split(TXTDAYS.Text, ",")
numberOfDates = UBound(tdates)
Dim counter As Integer
' loop through each input
For counter = 0 To numberOfDates
Dim xdate As String
xdate = LCase$(tdates(counter))
If Len(xdate) <= 2 Then
xcount = xcount + 1
Else
' if the original text has am or pm in it, add .5
If InStr(1, xdate, "am") > 0 Or InStr(1, xdate, "pm") > 0 Then
xcount = xcount + 0.5 'problem here it doesn't count
End If
End If
Next
如果有更好的方法可以通过检测逗号和 am pm 字符串来更好地执行此操作。