|
-
Aug 2nd, 2007, 03:09 PM
#1
Thread Starter
Hyperactive Member
timing
How can I count down from a number in seconds exactly?
My sister is always on the computer for too long now, and digging into my turn (sometimes by 1 hours 50 mins, as it was today) because we both have 1 computer with internet. As I have absolutelly no idea of what programme to make, apart from several complicated ones that I wont be able to do, I've decided to time her on the computer now. I hope it works, and It cant do that if you dont help me.
thankyou
i'm new so be nice
-
Aug 2nd, 2007, 03:23 PM
#2
Re: timing
use a timer object and set the interval propertie to 1000, being 1000 ms, equal to 1 second.
add a label to the form and put in the number of seconds you want to countdown from (if you prefer minutes, set the timer interval to 60000, making 60s, a minute)
In the timer's timer event, put the following code
VB Code:
Private Sub Timer1_Timer()
Label1.Value = Val(Label1.Value) - 1
If Val(Label1.Value) = 0 Then
MsgBox("Time's Up")
Timer1.Enabled = False
End If
End Sub
Delete it. They just clutter threads anyway.
-
Aug 2nd, 2007, 03:33 PM
#3
Re: timing
Add Timer control, label (I named it lblTime) and use code below - it will calculate ellapsed seconds and show formated value (hh:nn:ss) in the label:
Code:
Option Explicit
Dim strStartTime As String
Private Sub Form_Load()
strStartTime = Now
lblTime.Caption = "00:00:00"
Timer1.Interval = 1000 '1 second
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim lSecondsEllapsed As Long
lSecondsEllapsed = DateDiff("s", strStartTime, Now)
lblTime.Caption = Format(lSecondsEllapsed \ 3600, "00") & ":" & _
Format((lSecondsEllapsed \ 60) Mod 60, "00") & ":" & _
Format(lSecondsEllapsed Mod 60, "00")
End Sub
-
Aug 2nd, 2007, 03:38 PM
#4
Re: timing
On a second thought ... your sister may simply reopen your program to restart the counter... Ask your parents to buy you your very own computer (if they can afford it of course).
-
Aug 2nd, 2007, 03:50 PM
#5
Thread Starter
Hyperactive Member
Re: timing
I did a timer that used 3 different labels, hour, minute and second with colons inbetween, and if my sister tries to restart the counter by reopening the programme, wont it just set two counters next to each other? I've only done visual basic for a couple of weeks so i'm not that experienced.
-
Aug 2nd, 2007, 05:06 PM
#6
Hyperactive Member
Re: timing
Or on the form_unload you can just have it set where it left off in the registry :P Then pick that up the next time it opens on the form_load
"Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."
-
Aug 2nd, 2007, 09:15 PM
#7
Re: timing
Heh, that's a great idea, k0zz.
To the OP: Generally speaking, RhinoBull's method is the best one for this sort of thing.
As an evil aside, given your stated purpose, what I might do is when the timer runs out, bring up an AlwaysOnTop form that fills the screen so she cannot continue to use the computer pretty much at all once her time expires. If you toss in k0zz's registry suggestion even a reboot won't help.
All you'd need to do is add some sort of unlock password that lets the user "unlock" the computer by typing it into the AlwaysOnTop form.
heh.
If you think that would be fun, I can help you with all the complicated bits like using the registry and setting a form to be AlwaysOnTop and filling the screen.
-
Aug 2nd, 2007, 09:17 PM
#8
Re: timing
 Originally Posted by RhinoBull
On a second thought ... your sister may simply reopen your program to restart the counter... 
It's pretty easy to disallow ending a program unless some condition is true, like entering a valid password.
-
Aug 3rd, 2007, 12:27 AM
#9
Re: timing
if she isn't too great with computers the easiest way would be to disable the showintaskbar property in IDE and to set the borderstyle 'none'.
for as the task list (in the taskmanager), there was an easy way i don't remember...
anyway, if you'd compile the application with a name like svchost.exe, you would already have hidden the program in the processes list as there are already 5 or 6 of that application there.
on the desktop you simply add a shortcut to the application with a normal name.
Delete it. They just clutter threads anyway.
-
Aug 3rd, 2007, 12:50 AM
#10
Re: timing
a complete different way to do this, is give the app the time of day where your sisters time is up; kind of alarm clock like.
again with a timer you would check every minute whether the time has been reached.
the problem with this, though, is that you have to prevent her from changing the time, but that can also be solved by a more advanced close-by-handle function.
also this would be easier to combine with the registry as the alarm time is a fixed value.
Delete it. They just clutter threads anyway.
-
Aug 3rd, 2007, 07:48 AM
#11
Thread Starter
Hyperactive Member
Re: timing
 Originally Posted by TheBigB
if she isn't too great with computers the easiest way would be to disable the showintaskbar property in IDE and to set the borderstyle 'none'.
for as the task list (in the taskmanager), there was an easy way i don't remember...
anyway, if you'd compile the application with a name like svchost.exe, you would already have hidden the program in the processes list as there are already 5 or 6 of that application there.
on the desktop you simply add a shortcut to the application with a normal name.
I've just checked in the task manager for svchost.exe, and its there, and it will run all the time, and its important for something. If I name the programme after it, will it damage the computer in any way, because the computer will think: wait, there are 2 svchost.exes here, and it might stop doing one of them in order to do the other one, wont that damage the computer in some way?
-
Aug 3rd, 2007, 07:52 AM
#12
Re: timing
 Originally Posted by TheBigB
...anyway, if you'd compile the application with a name like svchost.exe....
I'm sorry pal but that is the worst idea anyone could come up with - under no sircumstances you would want to mess with system's apps.
-
Aug 3rd, 2007, 08:00 AM
#13
Thread Starter
Hyperactive Member
Re: timing
 Originally Posted by RhinoBull
I'm sorry pal but that is the worst idea anyone could come up with - under no sircumstances you would want to mess with system's apps.
what would happen if you did do that?
-
Aug 3rd, 2007, 08:05 AM
#14
Re: timing
Try it to find out for yourself.
-
Aug 3rd, 2007, 08:13 AM
#15
Thread Starter
Hyperactive Member
Re: timing
 Originally Posted by RhinoBull
Try it to find out for yourself. 
but my computer might blow up, then there would be no point in making the programme anyway.
-
Aug 3rd, 2007, 10:42 AM
#16
Re: timing
 Originally Posted by RhinoBull
I'm sorry pal but that is the worst idea anyone could come up with - under no sircumstances you would want to mess with system's apps.
why is that then?
giving it that name will only mask it in the list.
a more advanced user would be able to see that the svchost.exe running under a normal user (so not local service, networks service and system) would be the vb application.
Delete it. They just clutter threads anyway.
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
|