-
fill array with dates unique value
i loop with a for next this series of dates
...
02/01/2011 19.00.27
01/01/2011 19.00.14
01/01/2011 05.00.11
02/01/2011 05.00.02
...
i need to fill array with the most little date. In this case fill the array with:
01/01/2011 05.00.11
02/01/2011 05.00.02
-
ciao Luca,
I guess with "little date" you mean that you want the two "oldest" dates, is that right?
You can just compare the dates using the standard > and/or < operators, and store in an array the top two oldest ones.
Let me know.
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
 Originally Posted by mstraf
ciao Luca,
I guess with "little date" you mean that you want the two "oldest" dates, is that right?
You can just compare the dates using the standard > and/or < operators, and store in an array the top two oldest ones.
Let me know.
01/01/2011 05.00.11 <- Selected
01/01/2011 19.00.14
01/01/2011 21.21.11
02/01/2011 05.00.02 <- Selected
03/01/2011 01.00.03 <- Selected
03/01/2011 12.17.21
03/01/2011 18.00.27
if is most simple i post my question on other side:
Admitting i loop the series of value with a for next how to fill combobox items with the value marked with < - Selected
In effect i need to fill the items oin combo with the dates vale with the oldest time
note:
about that
"I guess with "little date" you mean that you want the two "oldest" dates, is that right?"
yes, sorry me
Last edited by luca90; 04-13-2011 at 12:52 PM.
-
 Originally Posted by luca90
01/01/2011 05.00.11 <- Selected
01/01/2011 19.00.14
01/01/2011 21.21.11
02/01/2011 05.00.02 <- Selected
03/01/2011 01.00.03 <- Selected
03/01/2011 12.17.21
03/01/2011 18.00.27
Actually it looks like you want the oldest entry for each date, so that you onlly have one entry in your list for each date. But since all of your dates were the first of each month, it could also be for each month and year rather than each date.
Here is some sample code that just shows how to load an array with just the dates you want. Assuming that if the date part is the same then grab the one with the oldest time. If the date part is not the same as any currently in the Array then add it to the Array.
How you get your list of dates I did not know, so I just left a comment that says '... get new date'.
Once you have the Date Array loaded you can then add those dates to your combo box list.
Here is the code:
Code:
Dim I As Long
Dim NewDate As Date
Dim DateArray() As Date
Dim DteCnt As Long
Dim NoMoreDates As Boolean
Do
' ... get NewDate from your list ... set NoMoreDates to true if last date
' ...NOTE: DteCnt is zero the first time through so the
' ...For Loop does not run its code; the first time through
' Check NewDate Against Date Array
For I = 1 To DteCnt
' Strip off the time part of the date to see
' if NewDate and DateArray are the same day
If CDate(Fix(DateArray(I))) = CDate(Fix(NewDate)) Then
' check to see if NewDate is older than DateArray
If NewDate < DateArray(I) Then
' NewDate was older so overite Item in DateArray
DateArray(I) = NewDate
End If
' a matching date was found in DateArray so stop looking
' in Date Array fo a match
Exit For
End If
Next I
' ... NOTE: if a match was found during the for loop then
' ... the loop exits early. Therefore 'I' will always be
' ... less than DteCnt
' ...
' ... If no match was found then the for loop completes and
' ... then 'I' will always be greater than DteCnt
' ...
' ... Also the first time DteCnt is zero so the loop completes
' ... and 'I' will be one, which is greater than DteCnt
' ... which means no match was found
' if no match was found in Date Array (i.e. I > DteCnt) then
' NewDate needs to be added to the DateArray
If I > DteCnt Then
' Increment DateArray Counter
DteCnt = DteCnt + 1
' Resize DateArray to hold new date
ReDim Preserve DateArray(1 To DteCnt)
' Save the NewDate in DateArray
DateArray(DteCnt) = NewDate
End If
Loop Until NoMoreDates = True
Similar Threads
-
By luca90 in forum VB Classic
Replies: 1
Last Post: 11-22-2010, 02:12 PM
-
By Tmcclain in forum Java
Replies: 7
Last Post: 02-13-2009, 11:57 PM
-
By MrComputerWhiz in forum Java
Replies: 4
Last Post: 02-04-2007, 10:45 AM
-
Replies: 4
Last Post: 08-14-2006, 11:01 PM
-
Replies: 6
Last Post: 11-01-2005, 10:05 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|