Last active
December 31, 2015 08:37
-
-
Save relyky/2c27e3f80de79d962254 to your computer and use it in GitHub Desktop.
vb6 date parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub ParseDate(ByRef tb As TextBox) | |
Rem 自訂函數 | |
On Error GoTo ErrHandle | |
Dim a As Long | |
Dim y, m, d As Integer | |
Dim mod4 As Long | |
y = Year(Now) | |
m = Month(Now) | |
d = Month(Now) | |
a = CLng(Replace(Replace(tb.Text, "/", ""), "-", "")) | |
Select Case a | |
Case Is < 100 ' 日 | |
d = a | |
Case Is < 10000 ' 月/日 | |
d = a Mod 100 | |
m = a / 100 | |
Case Is < 10000000 ' 年3/月/日 | |
mod4 = a Mod 10000 | |
d = mod4 Mod 100 | |
m = mod4 / 100 | |
y = a / 10000 + 2000 | |
Case Else ' 年/月/日 | |
mod4 = a Mod 10000 | |
d = mod4 Mod 100 | |
m = mod4 / 100 | |
y = a / 10000 | |
End Select | |
tb.Text = Format(y, "0000") & "/" & Format(m, "00") & "/" & Format(d, "00") | |
PROC_EXIT: | |
Exit Sub | |
ErrHandle: | |
tb.Text = "" ' FAIL | |
GoTo PROC_EXIT | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub txtFields_Validate(Index As Integer, Cancel As Boolean) | |
Rem 自訂訊息處理 | |
Select Case Index | |
Case 2, 6, 7, 8, 9 ' 日期欄位 | |
Debug.Print "txtFields_Validate 日期欄位" | |
Debug.Print txtFields(Index).Text | |
ParseDate txtFields(Index) | |
End Select | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment