| | |
Timer Control Help
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
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:
but it only subtracts once and stops. I tried using a loop but that also didn’t work :
Any ideas on how to solve this?
I was thinking along the line of this:
VB.NET Syntax (Toggle Plain Text)
Counter = (45 \ hsbSpeed.Value) - 1 txtCount.Text = Counter
VB.NET Syntax (Toggle Plain Text)
Counter = 45 \ hsbSpeed.Value Do While (Counter > 0) Counter = Counter - 1 Loop txtCount.Text = Counter
I haven't done any VB coding myself, but this:
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:
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.
VB.NET Syntax (Toggle Plain Text)
Do While (Counter > 0) Counter = Counter - 1 Loop txtCount.Text = Counter
Try this:
VB.NET Syntax (Toggle Plain Text)
Do While (Counter > 0) Counter = Counter - 1 txtCount.Text = Counter Loop
Please anyone, correct me if I am wrong. It is the best way for me to learn.
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
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:
Try something like this:
VB.NET Syntax (Toggle Plain Text)
Imports System.Threading Public Class Form1 Private BytesLeft As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click BytesLeft = 45 Do While BytesLeft txtCount.Text = (BytesLeft \ hsbSpeed.Value) - 1 txtCount.Refresh() Thread.Sleep(1000) BytesLeft -= hsbSpeed.Value Loop End Sub End Class
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
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.
![]() |
Similar Threads
- Visual Basic Timer/Clock/Countdown. (Visual Basic 4 / 5 / 6)
- ASP.Net timer control (ASP.NET)
- timer in VB.net (VB.NET)
- Help Using Visual Basic Timer (Visual Basic 4 / 5 / 6)
- timer starts from 00:00:00 (Visual Basic 4 / 5 / 6)
- Timer Question (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: how to make app always on top
- Next Thread: Updating a databound combobox
| Thread Tools | Search this Thread |
.net .net2008 2008 access add advanced application array basic beginner browser button buttons center click code combo cpu cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic employees excel exists fade filter forms generatetags html images input intel internet listview map mobile module monitor msaccess mysql net number objects open pan panel pdf picturebox picturebox2 port position print printing printpreview problem regex reuse right-to-left save search searchvb.net serial settings shutdown socket sqldatbase sqlserver storedprocedure survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol vb vb.net vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web winforms wpf wrapingcode xml year





