: Hello there
:
: I'm struggling with day, time functions and compare ..
: I'd like to run a piece a code if;
:
: 1. it's not a Saturday or Sunday and between Mytimes
: 2. and if it's between Mytimes compare how many minutes left before
: Myendtime then
: 3. execute code
:
:
:
: Dim myTime As Date
: myTime = Format(Now(), "hh:mm:ss tt")
:
:
: If vbSaturday Or vbSunday AndAlso myTime >= TimeSerial(7, 0, 0) _
: And vbSaturday Or vbSunday AndAlso myTime < TimeSerial(9, 55, 0) Then
: MsgBox ("1st piece")
: 'execute code here? give a comment on where the code is executed
: ElseIf myTime >= TimeSerial(10, 0, 0) And myTime < TimeSerial(15, 0, 0) Then
: MsgBox ("2nd piece")
:
: Else
: MsgBox ("3rd piece")
: End If
: :
:
: thanks Chris
i can see your problem or most of it anyways because i am doing timed events with my made from scratch program and i put in custom hours and minutes in my program but seconds doesnt work as well with me i tryed it.
code i changed:
If vbSaturday Or vbSunday AndAlso myTime >= TimeSerial(7, 0, 0) _
: And vbSaturday Or vbSunday AndAlso myTime <= TimeSerial(9, 55, 0) Then
'changed myTime < TimeSerial to myTime <= TimeSerial
: MsgBox ("1st piece")
: 'execute code here? give a comment on where the code is executed
: ElseIf myTime >= TimeSerial(10, 0, 0) And myTime <= TimeSerial(15, 0, 0) Then
'minutes between endtimes if thats what this is i dont think the above line will work set a timer and set the number of milli-seconds to the amount of seconds converted will equal the minutes you want. example 1000 milli-seconds equals 1 second i thinking out of memory or store the hours , minutes , and seconds in different variables to have custom selected time compares.
'Sample code for custom time variables: Dim StartHour,StartMinute,StartSecond as Integer
Dim EndHour,EndMinute2,EndSecond2 As integer
Dim StartTimeString as string
Dim EndTimeString as string
'should work but if this doesnt start with just the hour and minutes and that is way more likely to work
StartTimeString = CStr(StartHour) + ":"+ CStr(StartMinute) +":"+ CStr(StartSecond)
EndTimeString = CStr(EndHour) +":"+ CStr(EndMinute)+":"+CStr(EndSecond)
'my timed events are ones done at a selected time and date
: MsgBox ("2nd piece")
:
: Else
: MsgBox ("3rd piece")
: End If
hope this helps but if theres more post so you can get help