You'd start it when the timer started, and stop it when you stopped the timer. What DB is getting at is running a Stopwatch, which is just a high precision counter. So you have to recalculate the target time. When you start the timer again, it can't still be targeting 2:00pm, because that's only 5 minutes away, and you want to now target a time that is 15 minutes away (2:10pm), because that's what remains on your countdown. You let it run for ten minutes (1:45pm), then stop the timer for ten minutes until 1:55pm, so the timer is showing 15 minutes remaining. When you start, the target is "25 minutes from now", which might be 2:00 pm (which makes the current time 1:35pm). In other words, anywhere you start the timer, you have to also calculate TargetDT again. To do that, every time you start the timer, you have to calculate a new target time. What you are trying to create is a countdown that will run until it elapses, however long that is. In other words, what you have created is an alarm clock, where you set the time for it to go off, and as long as the timer is running, it is counting down towards that set target time. If you then stop the countdown for five minutes, then start it up again, you are still counting towards 2:00 pm, because that's your target time, but it's now five minutes closer to that target, so the countdown starts back up five minutes closer. ![]() Right now, you calculate the target time as something like 2:00 pm. That's effectively "some time in the future that is N minutes from the current time." If you stop the timer then start it a few seconds later, you have to recalculate that target time. Shaggy: When I pause the timer, I wait about forty seconds and then start it again, the display suddenly drops down those missing forty seconds.ĭbasnet: Will the stopwatch allow me to use minutes and seconds? If so, how do I input 25 minutes?Ah, now I see the problem, and I see what DB was getting at, too.ĭim ts As TimeSpan = TargetDT.Subtract(DateTime.Now) To address that, you'd have to put a breakpoint in the code and step through it, but since you are treating strings as if they were numbers, the issue could be entirely a result of that, so it might go away when you fix the variable confusion. Those suggestions don't directly address why you are jumping down two minutes. In this case, you want to pad to a length of two with the "0" character.įixing these issues may clear up the problems you are having, but they may not. What PadLeft does is extends the string to the desired length by filling to the left with the supplied character. ToString method of the variable, then use PadLeft to pad the string two two characters. However, also see the next note.Ģ) To show the integer variable, call the. For example "10" is less than "1" despite the fact that 10 is greater than 1. While such a comparison works, it doesn't always do what you expect it to do. There are lots of reasons to do this, but one is that you are liable to run into trouble with your final if statement because you are comparing strings using >. As it stands, you are doing a fair amount of implicit conversions from the strings in the labels to integers for the math, then back to strings to display. Use the labels ONLY to display the variables. As usual, thank you in advance for the help!ġ) Have integer variables to hold the minutes rather than using the labels. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.TickĮnd SubI want to avoid getting into setting up variables, if I can. Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click ![]() ![]() Code: Private Sub btnStart_Click_1(sender As Object, e As EventArgs) Handles btnStart.Click
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |