|
-
Apr 18th, 2005, 04:03 PM
#1
Thread Starter
Fanatic Member
Timer
I am going to make a timer that takes a message via an inputbox, then lets the user input a time via a text box and thes display the message that the inputbox got at the beginning in a message box, but I don't know how to make the message appear at the specified time. Here is my code, please help...
Code:
Option Explicit
Dim intmsg As Integer
Dim Txtstg As String
Private Sub Command1_Click()
If (Text1.Text = "") Or (Text1.Text = "- Time goes here -") Then
MsgBox "You have to type a number in either minutes or seconds!", vbOKOnly + vbCritical, "Error"
Else
Form1.Visible = False
End If
End Sub
Private Sub Form_Load()
Txtstg = Trim(InputBox("What do you want your message to say?", "What your message says", "Type here..."))
If Txtstg = "" Then
End
End If
End Sub
Private Sub Text1_Click()
If Text1.Text = "- Time goes here -" Then
Text1.Text = ""
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48) And (KeyAscii >= 32) Or (KeyAscii > 58) Then
KeyAscii = 0
End If
If Text1.Text = "- Time goes here -" And (KeyAscii > 47) And (KeyAscii < 58) Then
Text1.Text = ""
End If
End Sub
I need to make the message appear when the clock reaches the user-inputted time.
Thanks,
Sir loin
Last edited by Sir Loin; Apr 18th, 2005 at 05:31 PM.
-
Apr 18th, 2005, 04:22 PM
#2
Re: Timer
All you'd have to do is get the current time using something like this:
VB Code:
Dim CurTime As String
CurTime = Format(Time, "hh:mm:ss")
That is presuming that they enter the date in a hour:minute:second format.
Then, (Using a timer I suppose) check every 1000 miliseconds (1 second to you an me) - if they match then disable the timer and display the message 
Hoipe that helps,
RyanJ
-
Apr 18th, 2005, 05:00 PM
#3
Thread Starter
Fanatic Member
Re: Timer
Thanks for the help, but when I ask for the current time it says the time in military time, and the message doesn't appear when I type a time.
The code i'm using is
VB Code:
if text1.text = curtime then
do some stuff
end if
I am also using a timer to update the time every minute.
-
Apr 18th, 2005, 05:04 PM
#4
Re: Timer
 Originally Posted by Sir Loin
Thanks for the help, but when I ask for the current time it says the time in military time
I don't understand what you mean by "military time".
-
Apr 18th, 2005, 05:08 PM
#5
Thread Starter
Fanatic Member
Re: Timer
well when it was 5:00 it would say 17:00, and now that it is 6:00 it says 18:00.
-
Apr 18th, 2005, 05:09 PM
#6
Re: Timer
24-hour format is known as Military Time.
Just add the AMPM and it will be correct.
VB Code:
Option Explicit
Private Sub Form_Load()
Dim CurTime As String
CurTime = Format(Now, "h:mm:ss ampm")
CurTime = Left(CurTime, Len(CurTime) - 2) ' if you don't want the AMPM
End Sub
-
Apr 18th, 2005, 05:28 PM
#7
Thread Starter
Fanatic Member
Re: Timer
Thanks, but I need to know one more thing, how do I code a working clock that shows hours minutes and seconds?
Thanks,
Sir Loin
-
Apr 18th, 2005, 05:31 PM
#8
Thread Starter
Fanatic Member
Re: Timer
Never mind, I made one...
Thanks,
Sir Loin
-
Apr 18th, 2005, 05:46 PM
#9
Re: Timer
 Originally Posted by dglienna
24-hour format is known as Military Time.
Thanks, I didn't know that. I guess everone in my country is in the military then since we use the 24 hour system,
-
Apr 18th, 2005, 06:48 PM
#10
Thread Starter
Fanatic Member
Re: Timer
I have one final question, how do i make a form "Always on top" so even when it doesn't have focus it is still on top.
Thanks,
Sir Loin
-
Apr 18th, 2005, 06:55 PM
#11
Re: Timer
 Originally Posted by Sir Loin
I have one final question, how do i make a form "Always on top" so even when it doesn't have focus it is still on top.
That's a very common question. If you would have done a Forum search you would have found the code in no time. But here it is again:
VB Code:
Private Declare Function SetWindowPos Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Const HWND_NOTOPMOST As Long = -2
Private Const HWND_TOPMOST As Long = -1
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Sub TopMost(Optional blnTopMost As Boolean = True)
Dim hwndAfter As Long
If blnTopMost Then
hwndAfter = HWND_TOPMOST
Else
hwndAfter = HWND_NOTOPMOST
End If
Call SetWindowPos(Me.hwnd, hwndAfter, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
Simply call the TopMost sub. You can optionally pass True to set it topmost or False to not set it topmost (restore it). Default value is True.
-
Apr 18th, 2005, 06:59 PM
#12
Re: Timer
Use SetParent, which you use like this:
VB Code:
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
SetParent Me.hWnd, frmMain.hWnd
Where ME is the Child and frmMain is the Parent.
-
Apr 18th, 2005, 07:01 PM
#13
Re: Timer
 Originally Posted by dglienna
Use SetParent, which you use like this:
SetParent will not make a Form topmost.
-
Apr 18th, 2005, 07:34 PM
#14
Re: Timer
Hmmm. I have the SetParent in an MDI that does something like that. I'm going to save the SetWindow example.. Thanks.
-
Apr 18th, 2005, 08:35 PM
#15
Addicted Member
Re: Timer
Code:
Label1.Caption=format(time,"hh:mm:ss")
" I never did anything worth doing entirely by accident.... Almost none of my inventions were derived in that manner. They were achieved by having trained myself to be analytical and to endure and tolerate hard work."
" Many of life's failures are experienced by people who did not realize how close they were to success when they gave up. "
- Thomas Alva Edison-
In God We Trust 
-
Apr 18th, 2005, 09:16 PM
#16
Re: Timer
Are the clocks like this, too ? 
-
Apr 18th, 2005, 09:27 PM
#17
Re: Timer
 Originally Posted by dglienna
Are the clocks like this, too ? 
LOL, yeah sure! All kidding aside if a time table say 15:00 there can't be any confusion about the time but the AM/PM can be misunderstood. I guess that's why your military use that system as most of Europe does, except for the UK.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|