1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
Sub test()
Dim Dico As Object
Set Dico = CreateObject("System.Collections.SortedList")
Add Dico, "1/1/17 12:55"
Add Dico, "1/1/17"
Add Dico, "test12rd152"
Add Dico, "AAAAA"
ReDim r(Dico.Count - 1)
Dim i As Integer
For i = 0 To Dico.Count - 1
Debug.Print Dico.GetKey(i), Dico.GetByIndex(i)
r(i) = Dico.GetByIndex(i)
Next
End Sub
Sub Add(ByRef Dico As Object, value)
If CStr(value) = "" Then Exit Sub
If IsDate(value) And InStr(value, "/") And InStr(value, ":") Then Dico(CStr(Format(value, "yyyy-mm-dd hh:mm:ss"))) = value: Exit Sub
If IsDate(value) And InStr(value, "/") Then Dico(CStr(Format(value, "yyyy-mm-dd"))) = value: Exit Sub
Dico(CStr(ForamteTxt(value))) = value
End Sub
Public Function ForamteTxt(v)
Dim num As String, txt As String, i As Integer
For i = 1 To Len(v)
If IsNumeric(Mid(v, i, 1)) Then
num = num & Mid(v, i, 1)
Else
If num <> "" Then ForamteTxt = ForamteTxt & Format(num, String(13, "0")): num = ""
ForamteTxt = ForamteTxt & Mid(v, i, 1)
End If
Next
If num <> "" Then ForamteTxt = ForamteTxt & Format(num, String(13, "0"))
End Function |
Partager