Solved

Time Alert

Posted on 2001-06-18
7
211 Views
Last Modified: 2010-05-02
Hi All,
I am using vb6.  I want Alert after 1 hour from morning
8 till evening 8.  How i can detect time format.  If the
time is in AM or PM or Normal or how we can detect time
format from regional setting.  I need asap.
bye
0
Comment
Question by:Noor
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:CJHarrap
Comment Utility
Use a Timer Control to run an Event every 1 sec or so.... or whatever time you want. Add the Timer control to a form.

add this to top of form module.
dim mytime as string 'make mytime public

On the form load or under a command button use
mytime = format(inputbox("Enter Time to fire off alert"),"HH:MM:SS")

In the Timer event use something like
dim curtime as string
curtime = format(now(),"HH:MM:SS")

if mytime = currtime then
Msgbox "Alert"

End if


You get the idea....

Cheers,

CJ.

0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
Option Explicit

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub Main()

    Dim datTime As Date
    Dim lDelay As Long
   
   
    While True
   
    datTime = Now - Int(Now)
   
    If datTime >= 20 / 24 Then
   
        lDelay = DateDiff("s", datTime, TimeSerial(8, 0, 0) + 1)
       
    ElseIf datTime <= 8 / 24 Then
   
        lDelay = DateDiff("s", datTime, TimeSerial(8, 0, 0))
   
    Else
   
        lDelay = DateDiff("s", datTime, TimeSerial(Hour(datTime) + 1, 0, 0))
   
    End If
   
    lDelay = lDelay * 100
   
    Sleep lDelay

    MsgBox Time

    Wend

End Sub
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
ignore the above, should have been

Option Explicit

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub main()

    Dim datTime As Date
    Dim lDelay As Long
   
   
    While True
   
    datTime = Now - Int(Now)
   
    If datTime >= 20 / 24 Then
   
        lDelay = DateDiff("s", datTime, TimeSerial(8, 0, 0) + 1)
       
    ElseIf datTime <= 8 / 24 Then
   
        lDelay = DateDiff("s", datTime, TimeSerial(8, 0, 0))
   
    Else
   
        lDelay = DateDiff("s", datTime, TimeSerial(Hour(datTime) + 1, 0, 0))
   
    End If
   
    lDelay = lDelay * 1000
   
    Sleep lDelay

    MsgBox Time

    Wend

End Sub
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Noor
Comment Utility
It's great but if we run the exe and when we want to change
the Time from the Date/Time Properties, then the Date/Time Properties will hang. Any idea about this.  I am running Windows 98 OS
0
 
LVL 18

Accepted Solution

by:
deighton earned 30 total points
Comment Utility
'try this one

Option Explicit



Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub Main()

   Dim datLast As Date
   Dim datNow As Date
   
   datLast = Now
   datNow = Now
   
   If App.PrevInstance Then End
   
   Do
   
        If (Hour(datNow) - Hour(datLast)) = 1 And Hour(datNow) >= 8 And Hour(datNow) <= 20 Then
            MsgBox CDate(Now - Int(Now))
        End If
   
        datLast = datNow
        Sleep 500  
        DoEvents
        datNow = Now
   
    Loop Until False
       
               
End Sub
0
 

Author Comment

by:Noor
Comment Utility
No difference, Date-Time properties hanging
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
Option Explicit



Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub Main()

  Dim datLast As Date
  Dim datNow As Date
 
  datLast = Now
  datNow = Now
 
  If App.PrevInstance Then End
 
  Do
 
       If (Hour(datNow) - Hour(datLast)) = 1 And Hour(datNow) >= 8 And Hour(datNow) <= 20 Then
           MsgBox CDate(Now - Int(Now))
       End If
   
       datLast = datNow

       DoEvents
       datNow = Now
   
   Loop Until False
       
               
End Sub
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now