getxingbie() 中 Mid() 函数的第3个参数用错了。 还有都可以简化一下。 Private Function getbirthday(ByVal num As String) As String Dim temps As String
Select Case Len(num) Case 15 temps = Mid(num, 7, 2) + "-" + Mid(num, 9, 2) + "-" + Mid(num, 11, 2) Case 18 temps = Mid(num, 7, 4) + "-" + Mid(num, 11, 2) + "-" + Mid(num, 13, 2) Case Else Exit Function End Select
If Not IsDate(temps) Then Exit Function End If
getbirthday = temps End FunctionPrivate Function getxingbie(ByVal num As String) As String Dim temps As String Select Case Len(num) Case 15 temps = Mid(num, 15, 1) Case 18 temps = Mid(num, 17, 1) Case Else Exit Function End Select
If Not IsNumeric(temps) Then Exit Function End If
getxingbie = IIf((CInt(temps) Mod 2) = 0, "男", "女") End Function
------------------------------------------------------
18位:
xxxxxx20090101xxxx
15位:
xxxxxx090101xxx
------------------------------------------------------
性别不知道是最后一位还是哪个来着,忘了 - -
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
还有都可以简化一下。
Private Function getbirthday(ByVal num As String) As String
Dim temps As String
Select Case Len(num)
Case 15
temps = Mid(num, 7, 2) + "-" + Mid(num, 9, 2) + "-" + Mid(num, 11, 2)
Case 18
temps = Mid(num, 7, 4) + "-" + Mid(num, 11, 2) + "-" + Mid(num, 13, 2)
Case Else
Exit Function
End Select
If Not IsDate(temps) Then
Exit Function
End If
getbirthday = temps
End FunctionPrivate Function getxingbie(ByVal num As String) As String
Dim temps As String
Select Case Len(num)
Case 15
temps = Mid(num, 15, 1)
Case 18
temps = Mid(num, 17, 1)
Case Else
Exit Function
End Select
If Not IsNumeric(temps) Then
Exit Function
End If
getxingbie = IIf((CInt(temps) Mod 2) = 0, "男", "女")
End Function