I have this list of dates and hours txt file with:
20111018 235519
20111018 000445
20111014 235845
20111013 235321
20111012 235204
20111011 235331
20111010 235712
20111007 235549
20111006 235406
20111005 234828
20111004 235935
20111004 001240
i need the add items in combobox the new value of dates...
in this case from:
20111018 235519
20111018 000445
add this item 20111018- 000445
from
20111004 235935
20111004 001240
add this item 20111004-001240
note:
if exists a duplicate of dataes are alway near one to one, not possible to have the same date in other position.
loop in txt file and get the newest date
-
- PlatinumLounger
- Posts: 4373
- Joined: 26 Apr 2010, 17:36
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: loop in txt file and get the newest date
Hi sal,
You could read the text file's lines into an array, then sort the array before populating the combobox from the array.
To see how to sort an array, go to: http://www.cpearson.com/excel/SortingArrays.aspx" onclick="window.open(this.href);return false;
You could read the text file's lines into an array, then sort the array before populating the combobox from the array.
To see how to sort an array, go to: http://www.cpearson.com/excel/SortingArrays.aspx" onclick="window.open(this.href);return false;
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: loop in txt file and get the newest date
I've been playing with this using a 'Schema.ini' file to specify the column formats; thought I'd post out of interest:
But if your text file has column headings then it's a lot easier to import. Andy.
Code: Select all
Sub ReadCsvADO_Schema()
'The file Schema.ini must be in the same location as the text file,
'and has the following content (without apostrophes):
'[MyData.txt]
'Format = Delimited( )
'ColNameHeader=False
'Col1=aDate Long
'Col2=aTime Long
'
Dim cn As adodb.Connection
Dim rs As adodb.RecordSet
Set cn = New adodb.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Users\Andrew\Documents\TextImport\"";" _
& "Extended Properties=""text;HDR=No;FMT=Delimited"";"
Set rs = New adodb.RecordSet
'rs.Open "SELECT aDate, aTime FROM MyData.txt;", cn, adOpenStatic, adLockOptimistic, adCmdText
rs.Open "SELECT aDate, Max(aTime) AS MaxTime FROM MyData.txt GROUP BY aDate ORDER BY aDate;", cn, _
adOpenStatic, adLockOptimistic, adCmdText
With rs
MsgBox "There are " & .RecordCount & " records."
.MoveFirst
Do While Not .EOF
Debug.Print !aDate & "-" & Format(!MaxTime, "000000")
.MoveNext
Loop
End With
Set rs = Nothing
Set cn = Nothing
End Sub 'http://msdn.microsoft.com/en-us/library/ms974559.aspx
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.