D
Dennis D.
VB.net does not seem to have adequate structure for handling time
within it's own code.
Subtract 15 minutes from 00:00 AM, and an out of range condition results.
Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM,
as it should be.
Seems one half of the process is missing, and it is the half that requires
the most thought. Without it, we are left to hand code the whole process.
Time has a standard, and it should be properly implemented in the language.
Time is also one of the most commonly used routines in programming.
While I could work around the VB time construct programmatically, I feel
that the issue should be addressed. At least it should work with local time,
with only UTC conversion requiring additional code.
Why is it the way it is?
Here's the code:
Private Sub btnAction_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAction.Click
'begin StartText
Dim StartText As String = txbStart.Text
Dim HourParse As String = Mid(StartText, 1, 2)
Dim HourDbl As Double = Val(HourParse)
Dim HourInt As Integer = CInt(HourDbl)
Dim MinParse As String = Mid(StartText, 4, 2)
Dim MinDbl As Double = Val(MinParse)
Dim MinInt As Integer = CInt(MinDbl)
Dim SecInt As Integer = 0
Dim FunctionTime As Date = TimeSerial(HourInt, MinInt, SecInt)
Dim StartLabelText As String = Format(FunctionTime, "hh:mm tt")
'Set Start Time Label
lblStartUpR.Text = StartLabelText
'end StartText
'begin PreStart
Dim PreStart As String = txbPreStart.Text
HourParse = Mid(PreStart, 1, 2)
HourDbl = Val(HourParse)
HourInt = CInt(HourDbl)
MinParse = Mid(PreStart, 4, 2)
MinDbl = Val(MinParse)
MinInt = CInt(MinDbl)
'Begin Calc
Dim MinusHour As Double = HourDbl * -1
Dim MinusMin As Double = MinDbl * -1
Dim PreStartHour As Date = DateAdd(DateInterval.Hour, MinusHour,
CDate(txbStart.Text))
Dim PreStartHourDbl As Double = Val(PreStartHour)
Dim PreStartHourInt As Integer = CInt(PreStartHourDbl)
Dim PreStartMin As Date = DateAdd(DateInterval.Minute, MinusMin,
CDate(txbStart.Text))
Dim PreStartMinDbl As Double = Val(PreStartMin)
Dim PreStartInt As Integer = CInt(PreStartMinDbl)
FunctionTime = TimeSerial(HourInt, MinInt, SecInt)
StartLabelText = Format(FunctionTime, "hh:mm tt")
lblArrivalR.Text = PreStartMin.ToShortTimeString
End Sub
txbStart is a textbox. The time is entered in 24hour format as hh:mm.
lblStartUpR is a label that displays the time in short time format
txbPreStart is a textbox taking the same format.
lblArrivalR is a label that displays the time in short time format that is a
result of the following calculation:
txbPreStart is subtracted (by addition of a minus value) from txbStart
'Should I write simpler and tighter code to throw the exception?
within it's own code.
Subtract 15 minutes from 00:00 AM, and an out of range condition results.
Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM,
as it should be.
Seems one half of the process is missing, and it is the half that requires
the most thought. Without it, we are left to hand code the whole process.
Time has a standard, and it should be properly implemented in the language.
Time is also one of the most commonly used routines in programming.
While I could work around the VB time construct programmatically, I feel
that the issue should be addressed. At least it should work with local time,
with only UTC conversion requiring additional code.
Why is it the way it is?
Here's the code:
Private Sub btnAction_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAction.Click
'begin StartText
Dim StartText As String = txbStart.Text
Dim HourParse As String = Mid(StartText, 1, 2)
Dim HourDbl As Double = Val(HourParse)
Dim HourInt As Integer = CInt(HourDbl)
Dim MinParse As String = Mid(StartText, 4, 2)
Dim MinDbl As Double = Val(MinParse)
Dim MinInt As Integer = CInt(MinDbl)
Dim SecInt As Integer = 0
Dim FunctionTime As Date = TimeSerial(HourInt, MinInt, SecInt)
Dim StartLabelText As String = Format(FunctionTime, "hh:mm tt")
'Set Start Time Label
lblStartUpR.Text = StartLabelText
'end StartText
'begin PreStart
Dim PreStart As String = txbPreStart.Text
HourParse = Mid(PreStart, 1, 2)
HourDbl = Val(HourParse)
HourInt = CInt(HourDbl)
MinParse = Mid(PreStart, 4, 2)
MinDbl = Val(MinParse)
MinInt = CInt(MinDbl)
'Begin Calc
Dim MinusHour As Double = HourDbl * -1
Dim MinusMin As Double = MinDbl * -1
Dim PreStartHour As Date = DateAdd(DateInterval.Hour, MinusHour,
CDate(txbStart.Text))
Dim PreStartHourDbl As Double = Val(PreStartHour)
Dim PreStartHourInt As Integer = CInt(PreStartHourDbl)
Dim PreStartMin As Date = DateAdd(DateInterval.Minute, MinusMin,
CDate(txbStart.Text))
Dim PreStartMinDbl As Double = Val(PreStartMin)
Dim PreStartInt As Integer = CInt(PreStartMinDbl)
FunctionTime = TimeSerial(HourInt, MinInt, SecInt)
StartLabelText = Format(FunctionTime, "hh:mm tt")
lblArrivalR.Text = PreStartMin.ToShortTimeString
End Sub
txbStart is a textbox. The time is entered in 24hour format as hh:mm.
lblStartUpR is a label that displays the time in short time format
txbPreStart is a textbox taking the same format.
lblArrivalR is a label that displays the time in short time format that is a
result of the following calculation:
txbPreStart is subtracted (by addition of a minus value) from txbStart
'Should I write simpler and tighter code to throw the exception?