Re: Looking for some logic help with dates and working outs.
- From: "Larry Serflaten" <serflaten@xxxxxxxxxxxxxx>
- Date: Tue, 4 Dec 2007 08:00:47 -0600
"Kardon Coupé" <prefer.to@xxxxxxxxxxxxxxxxx> wrote
I would probably just use an Array of Dates and VB's Date functions toI've thought about that, as there are alot of code snippets around the web,
manage the changes.
showing how to work out if a leap year and such, but I really, really don't
want to be re-arranging and completly changing my code...
I would like to keep the exsist structure, and work from that.
You could still use a date array and keep your 'structure', but it
would involve indirection, and a few assumptions. On the plus
side, you'd save on memory, and file space if you chose to save
that data to the disk, and you'd get the proper date calculations for
free....
Instead of using multiple arrays, you could substitute in properties for
the array names, to keep your other code as it is. If handled properly,
you could still use statements like:
Y = E_Year(Index)
E_Day(Index) = 21
E_Minute(Index) = E_Minute(Index) + 15
(What other 'structure' are you using?)
The code accessing the data via a Date variable would automatically
account for roll-overs from minutes to hours and days to months (etc.)
including short months and leap years.
The indirection comes in, when you access your properties, you actually
extract the desired value from the date value. The assumptions happen
when you try to assign a value to one of the properties. If you assign a
value to E_Day, the assumption is made that the new value represents
days. Or if you assign a value to E_Minute, the assumtion is made that
the new value represents minutes. (et al.)
Just to keep it neat and clean you could put that in a separate (standard)
module which would contain code like the following; (only E_Day and
E_Minute are shown, others would be similar...)
Try it and see....
LFS
Option Explicit
Private E_Data(1 To 5000) As Date
Public Property Get E_Day(ByVal Index As Long) As Long
If ValidAccess(Index) Then
' Retrieve day value
E_Day = Day(E_Data(Index))
End If
End Property
Public Property Let E_Day(ByVal Index As Long, ByVal Value As Long)
Dim prev As Long
If ValidAccess(Index) Then
' Assign Day value
prev = Day(E_Data(Index))
E_Data(Index) = DateAdd("d", Value - prev, E_Data(Index))
End If
End Property
Public Property Get E_Minute(ByVal Index As Long) As Long
If ValidAccess(Index) Then
' Retrieve minute value
E_Minute = Minute(E_Data(Index))
End If
End Property
Public Property Let E_Minute(ByVal Index As Long, ByVal Value As Long)
Dim prev As Long
If ValidAccess(Index) Then
' Assign minute value
prev = Minute(E_Data(Index))
E_Data(Index) = DateAdd("n", Value - prev, E_Data(Index))
End If
End Property
Private Function ValidAccess(Index As Long) As Boolean
ValidAccess = (Index >= LBound(E_Data) And Index <= UBound(E_Data))
End Function
.
- Follow-Ups:
- Re: Looking for some logic help with dates and working outs.
- From: Steve Gerrard
- Re: Looking for some logic help with dates and working outs.
- From: Larry Serflaten
- Re: Looking for some logic help with dates and working outs.
- References:
- Looking for some logic help with dates and working outs.
- From: Kardon Coupé
- Re: Looking for some logic help with dates and working outs.
- From: Ralph
- Re: Looking for some logic help with dates and working outs.
- From: Kardon Coupé
- Looking for some logic help with dates and working outs.
- Prev by Date: Re: The inaugural VB6 vs dot net test
- Next by Date: Re: Looking for some logic help with dates and working outs.
- Previous by thread: Re: Looking for some logic help with dates and working outs.
- Next by thread: Re: Looking for some logic help with dates and working outs.
- Index(es):