|
-
Sep 14th, 2005, 02:06 AM
#1
Thread Starter
Addicted Member
Annoying Time format issue
Hi all,
I'm working on a program right now that restarts the computer at a set time, an "automatic shutdown" sort of tool. HERE and HERE are my previous threads on my issues with it, for more info.

My newest issue is this:
It's currently set so that when I use the left hand portion of the program (for shuttting down with a countdown timer) it will display the time currently, and how long until shutdown (a countdown).
When You use the right hand side of the form, it shows the time currently and at what time the specified time will be reached.
What I'm trying to do now is make the left hand side part display not only how long left until shut-down, counting down, but also the TIME at which it will shut down. For the right hand side, I want it to display how much time is left until shut-down. Basically I want to add the alternate features to either side.
For the left hand side, I tried to add "Time -" to the code, like so:
ORIGINAL CODE:
Code:
newTime = Time
diff = DateDiff("s", newTime, OldTime)
TTSD.Caption = (diff \ 60) & ":" & _
Format((diff - ((diff \ 60) * 60)), "00")
NEW CODE:
Code:
newTime = Time
diff = DateDiff("s", newTime, OldTime)
TTSD.Caption = (diff \ 60) & ":" & _
Format((diff - ((diff \ 60) * 60)), "00")
TSD.Caption = (Time - (diff \ 60) & ":") & _
Format((diff - ((diff \ 60) * 60)), "00")
After I tried this, this was the result that I got (for a clock set to 1 minute in the future):

1899? :S
I cannot simply copy the code that I am using from the right-hand side to display the time it will shut down, since all that does it print what's in those boxes on the right, which would be wrong since it's taking the time from the section on the left.
For the right hand side, I tried simple using code from the left to display the correct time:
Code:
newTime = Time
diff = DateDiff("s", newTime, OldTime)
TTSD.Caption = (diff \ 60) & ":" & _
Format((diff - ((diff \ 60) * 60)), "00")
However, when I activated the clock and timer, it came up showing this:

As you can see, It's not so easy to just copy the code across on this program. What I'm basically asking is two things:
1. How to take a time, and a countdown time in seconds, and add the countdown onto the "time" to produce an end-time
(This is so that for the left hand section, I can display not just how long LEFT until shutdown, but also at what TIME it will shutdown. Just like the section on the right)
2. What's the format for displaying one time minus another?
(This is so that for the right hand section, I can show not just WHEN it'll shut down, but also how long LEFT until shutdown. A shutdown timer, just like on the left)
Latest ZIP of my complete program:
Linky Mc Link
Thank you
Last edited by BubbleLife; Sep 14th, 2005 at 02:13 AM.
-
Sep 14th, 2005, 04:15 AM
#2
Lively Member
Re: Annoying Time format issue
Hi,
For a count down timer you can try using a timer whose interval is set to 1000. Then decrease the set time by 1 in every execution.
For example...
VB Code:
Private Sub Form_Load()
Timer1.interval = 1000
Timer1.enabled = true
RefreshInt = Val(TxtInterval.txt) * 60 ' Take the interval time from a text box
End Sub
Private Sub Timer1_Timer(ByVal RefreshInt as Integer )
RefreshInt = RefreshInt - 1
Lbl.Caption = RefreshInt & "seconds" ' For displaying the countdown in a label
If RefreshInt = 0 Then
'## Execute Main Function of scanning and cheking
' Run the function what ever you wish too when the countdown
DoFunction
End If
End Sub
For displaying the time left for shutdown.. try taking the current system time. Split it into a array and display some information on to a label or a text box after reducing the time shown in seconds in the first label from a the corresponding array index.
Hope it helps ...
--Putta
-
Sep 14th, 2005, 09:18 PM
#3
Thread Starter
Addicted Member
Re: Annoying Time format issue
 Originally Posted by putta
VB Code:
Private Sub Form_Load()
Timer1.interval = 1000
Timer1.enabled = true
RefreshInt = Val(TxtInterval.txt) * 60 ' Take the interval time from a text box
End Sub
Private Sub Timer1_Timer(ByVal RefreshInt as Integer )
RefreshInt = RefreshInt - 1
Lbl.Caption = RefreshInt & "seconds" ' For displaying the countdown in a label
If RefreshInt = 0 Then
'## Execute Main Function of scanning and cheking
' Run the function what ever you wish too when the countdown
DoFunction
End If
End Sub
The problem here is that, I don't have a text box that i can take an amount of seconds from. I have countdown timers working fine, the program is using it on this format. I'm assuming this is the solution for the right hand (click) side of the form?
For displaying the time left for shutdown.. try taking the current system time. Split it into a array and display some information on to a label or a text box after reducing the time shown in seconds in the first label from a the corresponding array index.
Hope it helps ...
--Putta
Could you explain to me how to use arrays though, please? I'm really a complete newbie to VB and we weren't taought that in the real basics of our course. Thanks
-
Sep 14th, 2005, 10:07 PM
#4
Re: Annoying Time format issue
Take a look at my countdown timer. It keeps perfect time.
Just use your dateadd instead of mine, which adds 300 seconds (5 minutes)
http://vbforums.com/attachment.php?attachmentid=38882
-
Sep 15th, 2005, 06:57 AM
#5
Thread Starter
Addicted Member
Re: Annoying Time format issue
I used that code for part of my program when you last posted in my thread, Thank you for that. However, I can't get that to work with this, since I'm not using a normal text field that I can get a variable from, but that special "Date" type one (but for time)
-
Sep 15th, 2005, 07:01 AM
#6
Re: Annoying Time format issue
Maybe you should focus on the function Dateadd
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Sep 15th, 2005, 07:15 PM
#7
Thread Starter
Addicted Member
Re: Annoying Time format issue
Last edited by BubbleLife; Sep 15th, 2005 at 07:30 PM.
-
Sep 16th, 2005, 05:37 PM
#8
Thread Starter
Addicted Member
Re: Annoying Time format issue
So to recap, all that's left needing sorting with the program now are two issues from the Date side of the form:
1. dtTime is displaying the current date, as well as the projected shutdown time
2. Still can't figure out a way of making a countdown timer that takes the current date and time, and the shutdown date and time, and calculates the seconds left until shutdown, and outputs that to the form (as the red text countdown) (Since i would have to make a variable as current TIME, produce a "diff" of the shutdown time (The main issue here is that it takes in both a Time AND DATE, and I can't simbly perform subtraction on it, as it's not the correct time value) and compare these two (Easy except for the previous mentioned problem)
Last edited by BubbleLife; Sep 16th, 2005 at 05:42 PM.
-
Sep 16th, 2005, 06:58 PM
#9
Re: Annoying Time format issue
Why not let the Task Sceduler handle for you? Just write the shutdown code as a separate program, and then use the AT command. You would have to SHELL it from VB. To get info, type AT /? from a command prompt.
-
Sep 16th, 2005, 07:12 PM
#10
Thread Starter
Addicted Member
Re: Annoying Time format issue
Whilst that would be possible, there are probably also other programs on the market that can do the same as this program, and others of mine. The point is that I like to make my own programs, and to learn from the coding that I do along the way, since my "Taught" VB is so minimal. From this project that I set myself, i've already learned about the workings of timers, and have started integrating them inot my programs (I wrote something else with a timer the other day).
That kind of progressive learning is what is getting me more able to do more with programs than the very basic first few commands that we learnt at college. It's not in the final result for me, but in the creation. I just host the programs on my site in case anyone might benefit from them. I doubt that my programs are as good as something anyone else could do but hey, i'm still learning 
The thing is, I'm SO close to finishing this program now. All I have to do is iron out these two bugs and it's complete. Whilst trying to figure out the last couple of bits of code, I've written another two programs. It's not that I'm getting frustrated with this program but It's just that everything is working except these last couple of bits, and I really want to finish it now.
Are the two problems that I described not fixible, then?
-
Sep 16th, 2005, 07:53 PM
#11
Re: Annoying Time format issue
I added this line to compute the shutdown date
VB Code:
TSD = DateAdd("d", DateDiff("d", Date, dtDate), Date)
You can play around with it to add the time, but you'd have to check if the date is greater than today, and if so, add 1 days worth of seconds to each datediff. That way you could use your other code to calculate # of hours.
-
Sep 17th, 2005, 11:42 AM
#12
Thread Starter
Addicted Member
Re: Annoying Time format issue
*Thinks for a minute*
Ahh, I think that's code to make it display the "Time Of Shutdown" when "Countdown" is used, correct? (This project is starting to confuse me now...)
I already got that bit working (see end of last big post), thank you though 
I just re-read my last "To recap" post.. It doesn't make much sense, i'll admit.
The problems left in my program are:
* When using the "Clock/Shutdown" section, it displays the current date as well as the projected date of shutdown (You explained about that)
* When using the "Clock/Shutdown" section, I'd like to make a way of utilising the red "Time remaining until shutdown" section, which will count down from that current date/time (the real time when "Set" is pressed) until the one set by the controls in that frame is reached (at which time the computer will restart)
EDIT: Just found another error:
A) In "Countdown", settigng especially large "Hour" figures (Max are 500 in hours, 999 in minutes, 9999 in seconds) make it appear with a date which is completely wrong (like 1900 or 1899). I'm obviously not sure if this is actually the date it'll try and shut down (IOW, it actually breaks the code) or not, but either way it's wrong. This appears to happen after the 10th hour
B) Some values in "Hours", below 500 (Like 80 and 6) make it come up with the "Please enter 500 hours or less" validation which is supposed to only kick in if the value is over 500. I had to remove the code for validating mins and secs since it stopped the code working completely).
Here is the code for that section:
Code:
If UTi = True Then
If Hrs = "" Or Mins = "" Or Secs = "" Then
MsgBox "Please enter a value in all 3 boxes. If you don't want to use a box, enter a '0' in it.", , "Incorrect input"
Exit Sub
End If
If Hrs > "500" Then
MsgBox "Please enter 500 or less for hours.", , "Error in input"
Exit Sub
End If
Thanks
-
Sep 17th, 2005, 12:22 PM
#13
Re: Annoying Time format issue
I think you want the countdown for a date to show
x Days, x Hours, x Minutes, x Seconds
Set a flag if it is the current is the right day to shutdown, if so, don't print the days. Just hours, min, sec!
It would start out at 1 day, 6 hours... and after 6 hours, change to 24 hours...
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
|