Click to See Complete Forum and Search --> : Save / Set timer
CyberCarsten
Nov 19th, 1999, 03:42 AM
Hi!
I'm building a program that can
shutdown the computer after a
certain time.
Then i want the user to
adjust the timer interval, but i can't
get it to work!!
The must retrieve the timer-interval
from the registry or from a file...etc...
/ CyberCarsten [^Cc^]
Aaron Young
Nov 19th, 1999, 03:48 AM
Try using the Timer Function in conjunction with a Timer Control, eg.
Private tInterval As Long 'Interval in Minutes
Private Sub Timer1_Timer()
Static tTimer As Single
If tTimer = 0 Then tTimer = Timer
If (Timer - tTimer) >= (tInterval * 60) Then
'ShutDown the Computer
Timer1.Enabled = False
End If
End Sub
Then, to Adjust, Save/Restore the Interval, simply Modify the value of tInterval in Minutes.
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
razzaj
Nov 19th, 1999, 07:11 AM
well .. what young proposed is fine ...
but this way when the computer starts again
the time the user set will be erased because it is in memory.
using registry is fine but here is a simpler way :
start a blanc project
- insert a timer control
- insert a text control
- insert a command button
in module :
Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long
public Const EWX_SHUTDOWN = &H1
public timetoclose as long
in form code :
- in text_keypress
if keyascii = 13 and text1 <> "" then
open "c:\shutdown.set" for output as #1
print #1 , text1
close #1
timetoclose = val (text1) * 1000
me.hide
initcounter
end if
- in timer1_timer
timer1.enabled = false
ExitWindowsEx EWX_SHUTDOWN
end sub
- in form_load
dim a as string
open "c:\shutdown.set" for input as #1
input #1 , a
close #1
text1 = val(a)
timetoclose = text1* 1000
initcounter
end sub
- in command1_click
me.hide
initcounter
end sub
- create a sub called initcounter
public function initcounter ()
timer1.interval = timetoclose
timer1.enabled = true
end function
user's manual :
-------------------
1 - i think that is it i havent tried it
but if u have any problem just message me
back.
2 - ur aim was not too clear so i tryed to
give the most satisfying answer
3- before starting the program just go to
"c:\" and create a file called
"shutdown.set" write in it anything
a number for instance u need to do this
only the first time u run the program
. icould have given u a more complete
code but it is late now i have to sleep .
4- when the form shows input in the textbox
a number (minutes) and PRESS ENTER
5- if the next time u start the program
u dont want to change the time just press
the command button
6 - i know this is far form being the best
and efficient code but i really feel
sleepy.
7 - if u need any help again .... just
message me anytime i ll be gald to help
- Regards -
- razzaj -
CyberCarsten
Nov 19th, 1999, 05:34 PM
Thanx guys!!!
CyberCarsten
Nov 19th, 1999, 06:09 PM
razzaj , that didn't work...
Aaron Young
Nov 19th, 1999, 10:56 PM
The Code I Posted will work, all you have to do is save/set the value of tInterval, eg.
Private tInterval As Long 'Interval in Minutes
Private Sub Timer1_Timer()
Static tTimer As Single
Dim lSecs As Long
Dim iMins As Integer
Dim iHrs As Integer
If tTimer = 0 Then tTimer = Timer
If (Timer - tTimer) >= (tInterval * 60) Then
'ShutDown the Computer
Timer1.Enabled = False
End If
lSecs = (tInterval * 60) - Int(Timer - tTimer)
iHrs = Int((lSecs / 60) / 60)
iMins = Int((lSecs / 60) - (iHrs * 60))
lSecs = (lSecs - (iMins * 60) - (iHrs * 360)) Mod 60
Caption = "Shutdown in " & _
Right("00" & iHrs, 2) & ":" & Right("00" & iMins, 2) & ":" & Right("00" & lSecs, 2)
End Sub
Private Sub Form_Load()
'Get the Stored Time Interval, Default to 1 Hour (60 Mins).
tInterval = Val(GetSetting(App.Title, "Interval", "Value", "60"))
If MsgBox("Do You Wish to Change the Time Interval?" & _
vbCrLf & vbCrLf & _
"It is Currently.. " & tInterval & _
" Minutes.", vbQuestion + vbYesNo, "Timer Interval") = vbYes Then
tInterval = Val(InputBox("Enter a new Interval in Minutes: ", "Set Interval", _
tInterval))
End If
'Save the Interval to the Registry
SaveSetting App.Title, "Interval", "Value", Trim(Str(tInterval))
Timer1.Interval = 100
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
CyberCarsten
Nov 20th, 1999, 11:31 AM
Thank you Aaron!!!
That worked!! : - )
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.