I use the tipical free file eof .... to read line by line a txt file.
During the loop a get in a mid postion of string a date form each lines and store the date value it in mYDate var.
How to get the min and max date when the loop is finished?
Peraphs i can store the date value in a collection, in a dictionary...
note:
In txt are approx 350.xxx lines
SUGGEST to get min max date from txt string
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: SUGGEST to get min max date from txt string
I'll take a chance to reply...
You can try Dim myDate() as Variant
Then in your loop have a counter like: i=i+1 and populate your variable myDate(i)
Lastly use the LBound(myDate) to extract the Min Date and UBound(myDate) to extract the Max date.
You can try Dim myDate() as Variant
Then in your loop have a counter like: i=i+1 and populate your variable myDate(i)
Lastly use the LBound(myDate) to extract the Min Date and UBound(myDate) to extract the Max date.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78440
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: SUGGEST to get min max date from txt string
Try code like this:
Code: Select all
Dim myDate As Date
Dim minDate As Date
Dim maxDate As Date
Dim strLine As String
minDate = #1/1/2100#
maxDate = #1/1/1900#
Dim f As Integer
f = FreeFile
Open "C:\MyFile.txt" For Input As #f
Do While Not EOF(f)
Line Input #f, strLine
myDate = CDate(Mid(strLine, 24, 10))
If myDate > maxDate Then
maxDate = myDate
End If
If myDate < minDate Then
minDate = myDate
End If
Loop
Close #f
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: SUGGEST to get min max date from txt string
Sorry me Hans,HansV wrote:Try code like this:
Code: Select all
Dim myDate As Date Dim minDate As Date Dim maxDate As Date Dim strLine As String minDate = #1/1/2100# maxDate = #1/1/1900# Dim f As Integer f = FreeFile Open "C:\MyFile.txt" For Input As #f Do While Not EOF(f) Line Input #f, strLine myDate = CDate(Mid(strLine, 24, 10)) If myDate > maxDate Then maxDate = myDate End If If myDate < minDate Then minDate = myDate End If Loop Close #f
but i'm inattentive...
i have two var
mYDate and mYDate1
based mYDate i need only the min date an based mYDate1 only the max date
-
- Administrator
- Posts: 78440
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: SUGGEST to get min max date from txt string
i get also other value from the each string with myDate1 = CDate(Mid(strLine, 68, 10))HansV wrote:Sorry, I don't understand.
now i need to get, during the loop only the min date with...
myDate = CDate(Mid(strLine, 24, 10))
and i need to get, during the loop only the max date...
myDate1 = CDate(Mid(strLine, 68, 10))
-
- Administrator
- Posts: 78440
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: SUGGEST to get min max date from txt string
OK, try this version:
Code: Select all
Dim myDate As Date
Dim myDate1 As Date
Dim minDate As Date
Dim maxDate As Date
Dim strLine As String
minDate = #1/1/2100#
maxDate = #1/1/1900#
Dim f As Integer
f = FreeFile
Open "C:\MyFile.txt" For Input As #f
Do While Not EOF(f)
Line Input #f, strLine
myDate = CDate(Mid(strLine, 24, 10))
If myDate < minDate Then
minDate = myDate
End If
myDate1 = CDate(Mid(strLine, 68, 10))
If myDate1 > maxDate Then
maxDate = myDate1
End If
Loop
Close #f
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: SUGGEST to get min max date from txt string
HansV wrote:OK, try this version:
Code: Select all
Dim myDate As Date Dim myDate1 As Date Dim minDate As Date Dim maxDate As Date Dim strLine As String minDate = #1/1/2100# maxDate = #1/1/1900# Dim f As Integer f = FreeFile Open "C:\MyFile.txt" For Input As #f Do While Not EOF(f) Line Input #f, strLine myDate = CDate(Mid(strLine, 24, 10)) If myDate < minDate Then minDate = myDate End If myDate1 = CDate(Mid(strLine, 68, 10)) If myDate1 > maxDate Then maxDate = myDate1 End If Loop Close #f
Genius!
... to understand me
... and for the brilliant code