Making a timer application.
Making a timer application.
Morning guys.
I am trying to make a timer application. Whereby I can input a timestamp into a form, press start and then, when I press stop, it will tell me how long it was till I pressed the stop. I want 8 of these, so I presume I just repeat the code 8 times for each timestamp, correct?
But, it's the actual code that I am unsure of on how to do. Anyone got any ideas on how to do this?
Thanks guys!
I am trying to make a timer application. Whereby I can input a timestamp into a form, press start and then, when I press stop, it will tell me how long it was till I pressed the stop. I want 8 of these, so I presume I just repeat the code 8 times for each timestamp, correct?
But, it's the actual code that I am unsure of on how to do. Anyone got any ideas on how to do this?
Thanks guys!
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
platform?
language?
you're talking forms... can we presume some flavour of vb?
if all you're doing is tracking snapshots of the system clock... normally stored as a long integer, (64bits). you would take the initial snapshot when start is pressed and the comparative when stop is pressed... the difference between the two is the time elapsed...
you use a timer when you require some form of automation... ie, no user intervention...
if you require that the form output be updated between presses, then you need a seperate thread running which can handle that for you, leaving the execution thread free to trap events. how you do this depends on the platform/language being used...
language?
you're talking forms... can we presume some flavour of vb?
if all you're doing is tracking snapshots of the system clock... normally stored as a long integer, (64bits). you would take the initial snapshot when start is pressed and the comparative when stop is pressed... the difference between the two is the time elapsed...
you use a timer when you require some form of automation... ie, no user intervention...
if you require that the form output be updated between presses, then you need a seperate thread running which can handle that for you, leaving the execution thread free to trap events. how you do this depends on the platform/language being used...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
In VB.NET
Assuming you have two buttons on the form. First button stamps, second calculates.
Code: Select all
Dim dtTimeStamp As DateTime
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dtTimeStamp = DateTime.Now() ' start
MessageBox.Show(dtTimeStamp.ToString("hh:mm:ss"))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MessageBox.Show(((DateTime.Now().Ticks() - dtTimeStamp.Ticks()) / 1.0E+7F).ToString() + "s") ' stop
End Sub
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Divide by 10,000,000 and convert to float. Will convert ticks to seconds. It would normally read:
but the IDE changes it.
Code: Select all
/10000000f
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
You need to make it global so you can use it in separate functions. It needs to be defined outside of any subs or functions.Hex_Rated: That seems like what I want. The only part I don't understand is what control/code do I use to declare the 'dtstamptime' ?
You can make 8 separate vars, an array would work best but you could give them separate names as well if you aren't comfortable with arrays yet. You need a separate dtTimeStamp var for each timer. Use the same calculation just substitute the variable name for the one your trying to work out.Can I repeat the code for 8 boxes ect?
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
All you need to do is put
Anywhere in your form as long as it's not inside a subroutine. Let's say you double clicked a button on your form designer and it created this code for you:
You can put the dtTimeStamp declaration immediately above it:
Now it will be global and accessible to any sub routine in that form.
Code: Select all
Dim dtTimeStamp as DateTime
Code: Select all
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Code: Select all
Dim dtTimeStamp as DateTime
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
No. Create two buttons and put the code underneath their events. The IDE will create the sub routine definitions, just copy the code underneath the sub .. till end sub in each event handler. When you click the first button the time will be displayed, when you click the second button the difference in time will be displayed in seconds.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
C# isn't any more efficient than VB.NET. They both end up as byte code and are compiled to native code at run time by a dynamic compiler. C++ and assembler are far more efficient but you would be mad to use them to write an application where you need low development overhead or where performance isn't critical.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
8O OK, could you write an application in assembler that connects to an Oracle 10g database, allows you to browse and edit a table displaying the information on text boxes on a form in under 20 minutes? What if the client wanted to change it to a MySQL database? How long would it take?And there is nothing wrong with writing entire applications in nothing but assembler.
Don't get me wrong, assembler is extremely important since it is as close to a CPU's native language as you can get without replacing the opcodes with numbers but in this day and age it is not very useful outside engineering. Even when working with drivers for embedded micro controllers, I hardly ever come across it any more. Shaders for graphics cards were written in assembler, even they are using Cg or HLSL these days AFAIK.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
I dont use databases, and if I were to then, yes, something like C# would be better.
I write all drivers in about 60% inline assembly the rest in C.
I've written entire rootkits in assembly as well.
Writing gui's in assembly, only really takes a bit longer than doing it in C/C++.
Every programmer should know at least basic assembly (for disassembly purposes)
I write all drivers in about 60% inline assembly the rest in C.
I've written entire rootkits in assembly as well.
Writing gui's in assembly, only really takes a bit longer than doing it in C/C++.
Every programmer should know at least basic assembly (for disassembly purposes)
Punkbuster bypass? You planning on cheating in battlefield or something?
If you're reverse engineering and cracking, assembler is definitely the way to go. For most commercial applications, you wouldn't encounter it unless (as you said) you need to view the disassembly for debugging purposes, which is rare.
If you're reverse engineering and cracking, assembler is definitely the way to go. For most commercial applications, you wouldn't encounter it unless (as you said) you need to view the disassembly for debugging purposes, which is rare.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64