Time Compare Function Problems

S

scorpion53061

Could you look at this function and tell me why I am getting an
exception concerning date cast on line set apart by stars... If you have
better suggestions of how to do this I would be open to suggestions.


Public Function JobStreamCheck() As Boolean
Dim hour As Integer
Dim day As Integer
Dim year As Integer
Dim month As Integer
Dim ActionTime As DateTime 'time action is occuring that we are
checking to make sure no jobstream is running. Time obtained from SQL
using GetDate 'formatted as say for example 4:15 PM . Start and End
Times are also gotten from SQL but for this example they are declared
locally

Dim JobStreamStart As DateTime
Dim jobstreamend As DateTime

month = Format(ActionTime, "MM")
hour = Format(ActionTime, "HH")
day = Format(ActionTime, "dd")
year = Format(ActionTime, "yyyy")

JobStreamStart = Format(JobStreamStart, month & "/" & day & "/"
& year & " hh:mm tt")

If Format(JobStreamEnd, "HH:mm tt") > Format("23:59 PM", "HH:mm
tt") Then
JobStreamEnd = (JobStreamEnd, month & "/" & day + 1 & "/" &
year & " HH:mm tt")) 'move day ahead one because job stream will be in
new day
Else
'********EXCEPTION THROWN
jobstreamend = Format(jobstreamend, month & "/" & day & "/"
& year & " HH:mm tt") 'job stream will finish in same day
'*******EXCEPTION THROWN END
End If

If ActionTime >= JobStreamStart And ActionTime < jobstreamend
Then
Return True ' Job stream is running dont allow login
Else

Return False ' job stream is not running so allow login
End If
End Function
 
J

Jay B. Harlow [MVP - Outlook]

Scorpion,
I would (still) recommend a TimeRange as identified in my response the last
time you asked this question:

http://groups-beta.google.com/group/microsoft.public.dotnet.languages.vb/msg/2eaea1681fe04f3c?hl=en

Then the JobStreamCheck routine becomes:

Public Function JobStreamCheck() As Boolean
Dim ActionTime As DateTime = ...

Dim JobStreamStart As DateTime = ...
Dim JobStreamEnd As DateTime = ...

Dim JobStreamRange As New TimeRange(JobStreamStart, JobStreamEnd)

If JobStreamRange.Contains(ActionTime) Then
Return True
Else
Return False
End If

End Function

Hope this helps
Jay

| Could you look at this function and tell me why I am getting an
| exception concerning date cast on line set apart by stars... If you have
| better suggestions of how to do this I would be open to suggestions.
|
|
| Public Function JobStreamCheck() As Boolean
| Dim hour As Integer
| Dim day As Integer
| Dim year As Integer
| Dim month As Integer
| Dim ActionTime As DateTime 'time action is occuring that we are
| checking to make sure no jobstream is running. Time obtained from SQL
| using GetDate 'formatted as say for example 4:15 PM . Start and End
| Times are also gotten from SQL but for this example they are declared
| locally
|
| Dim JobStreamStart As DateTime
| Dim jobstreamend As DateTime
|
| month = Format(ActionTime, "MM")
| hour = Format(ActionTime, "HH")
| day = Format(ActionTime, "dd")
| year = Format(ActionTime, "yyyy")
|
| JobStreamStart = Format(JobStreamStart, month & "/" & day & "/"
| & year & " hh:mm tt")
|
| If Format(JobStreamEnd, "HH:mm tt") > Format("23:59 PM", "HH:mm
| tt") Then
| JobStreamEnd = (JobStreamEnd, month & "/" & day + 1 & "/" &
| year & " HH:mm tt")) 'move day ahead one because job stream will be in
| new day
| Else
| '********EXCEPTION THROWN
| jobstreamend = Format(jobstreamend, month & "/" & day & "/"
| & year & " HH:mm tt") 'job stream will finish in same day
| '*******EXCEPTION THROWN END
| End If
|
| If ActionTime >= JobStreamStart And ActionTime < jobstreamend
| Then
| Return True ' Job stream is running dont allow login
| Else
|
| Return False ' job stream is not running so allow login
| End If
| End Function
|
 
S

scorpion53061

Jay,

In fact I looked in my archive and sure enough it was there. Turned out
I had lost the project it was in.

Thank you much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Time Problem 6
time formatting error 2
DateTimePicker and saving time only.. 1
Adding time to date 8
Conversion Rome time to New York Time 7
Code Optimization 0
DateTimePicker 2
Lost time part of datetime datatype 6

Top