Timer Control Help

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 2
Reputation: Panachski is an unknown quantity at this point 
Solved Threads: 0
Panachski Panachski is offline Offline
Newbie Poster

Timer Control Help

 
0
  #1
Nov 6th, 2006
Hi, I am a newcomer to Visual Studio 2005 and am having trouble making a timer which will work out the time it takes to download a file. The file is 45 kb and the user can change the speed with a scrollbar, which is called hsbSpeed, from 1 – 10 kbps. The timer will then work out the download time and count down to zero.

I was thinking along the line of this:

  1. Counter = (45 \ hsbSpeed.Value) - 1
  2. txtCount.Text = Counter
but it only subtracts once and stops. I tried using a loop but that also didn’t work :

  1. Counter = 45 \ hsbSpeed.Value
  2. Do While (Counter > 0)
  3. Counter = Counter - 1
  4. Loop
  5. txtCount.Text = Counter
Any ideas on how to solve this?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: Timer Control Help

 
0
  #2
Nov 6th, 2006
I haven't done any VB coding myself, but this:
  1. Do While (Counter > 0)
  2. Counter = Counter - 1
  3. Loop
  4. txtCount.Text = Counter
Looks like it will keep iterating down until the variable Counter is equal to zero, and then it will set the Text value of txtCount to 0.
Try this:
  1. Do While (Counter > 0)
  2. Counter = Counter - 1
  3. txtCount.Text = Counter
  4. Loop
You will probably also want to slow the loop down so that it only loops once per second. Perhaps pull the system time at the start of the loop and then wait at the end of the loop until the system time is equal to that time + 1.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Timer Control Help

 
0
  #3
Nov 6th, 2006
Your file is 45kb and say your speed is set to 5kb. You are setting your counter to 45/5 every time. Set a variable called say "BytesLeft". After you have read 5kb subtract it from you "BytesLeft".
Try something like this:
  1. Imports System.Threading
  2.  
  3. Public Class Form1
  4. Private BytesLeft As Integer
  5.  
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7. BytesLeft = 45
  8. Do While BytesLeft
  9. txtCount.Text = (BytesLeft \ hsbSpeed.Value) - 1
  10. txtCount.Refresh()
  11. Thread.Sleep(1000)
  12. BytesLeft -= hsbSpeed.Value
  13. Loop
  14. End Sub
  15. End Class
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 2
Reputation: Panachski is an unknown quantity at this point 
Solved Threads: 0
Panachski Panachski is offline Offline
Newbie Poster

Re: Timer Control Help

 
0
  #4
Nov 8th, 2006
Thanks for the help guys, I had tried something similar to the code that you gave me David but it didn't work. We have to explain our coding and show the lecturer how so the code that you kindly showed me Wayne was a bit too complicated. In the end I figured out a different way to do it but thanks all the same.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC