Solved

Time Alert

Posted on 2001-06-18
7
212 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
ID: 6201382
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
ID: 6201408
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
ID: 6201417
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Noor
ID: 6202425
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
ID: 6206027
'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
ID: 6213263
No difference, Date-Time properties hanging
0
 
LVL 18

Expert Comment

by:deighton
ID: 6213418
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

911 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

23 Experts available now in Live!

Get 1:1 Help Now