Making a timer application.

Get help on programming - C++, Java, Delphi, etc.
Tander
Registered User
Posts: 417
Joined: 06 May 2007, 02:00
Location: Johannesburg, South Africa

Making a timer application.

Post by Tander »

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!
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

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...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
HdB
Registered User
Posts: 929
Joined: 18 Oct 2004, 02:00
Location: Bloemfontein
Contact:

Post by HdB »

Normally you should get the system time when you click the Start button, and again when you click the Stop button.

The compute the difference between the two. I THINK .NET can show the difference in miliseconds, or ticks, not quite sure.
AMD Athlon 64 X2 4800+ s939 | Gecube 3870 OC edition
Image
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

In VB.NET

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
Assuming you have two buttons on the form. First button stamps, second calculates.
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
HdB
Registered User
Posts: 929
Joined: 18 Oct 2004, 02:00
Location: Bloemfontein
Contact:

Post by HdB »

@Hex_Rated:

Sorry for my ignorance, but what does this part do?
/ 1.0E+7F
AMD Athlon 64 X2 4800+ s939 | Gecube 3870 OC edition
Image
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

Divide by 10,000,000 and convert to float. Will convert ticks to seconds. It would normally read:

Code: Select all

/10000000f
but the IDE changes it.
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
Tander
Registered User
Posts: 417
Joined: 06 May 2007, 02:00
Location: Johannesburg, South Africa

Post by Tander »

Yes, sorry VB is what I am using.

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' ?

Can I repeat the code for 8 boxes ect?
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

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 need to make it global so you can use it in separate functions. It needs to be defined outside of any subs or functions.
Can I repeat the code for 8 boxes ect?
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.
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
Tander
Registered User
Posts: 417
Joined: 06 May 2007, 02:00
Location: Johannesburg, South Africa

Post by Tander »

Hex_Rated wrote:
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.
Sorry, Hex_Rated, I am still fairly new to all this. Do you mean I need to make it in its own class, then what code goes there? Just a timer?
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

All you need to do is put

Code: Select all

Dim dtTimeStamp as DateTime
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:

Code: Select all

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
End Sub
You can put the dtTimeStamp declaration immediately above it:

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
Now it will be global and accessible to any sub routine in that form.
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
Tander
Registered User
Posts: 417
Joined: 06 May 2007, 02:00
Location: Johannesburg, South Africa

Post by Tander »

Makes sense.

Thank you, will give it ago. Do I need text boxes on the form?
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

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
Tander
Registered User
Posts: 417
Joined: 06 May 2007, 02:00
Location: Johannesburg, South Africa

Post by Tander »

Thanks, Hex. Will try it out now. :D
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

Step one:
Learn a real language
Tander
Registered User
Posts: 417
Joined: 06 May 2007, 02:00
Location: Johannesburg, South Africa

Post by Tander »

PHR33K wrote:Step one:
Learn a real language
And that would be? :roll:
HdB
Registered User
Posts: 929
Joined: 18 Oct 2004, 02:00
Location: Bloemfontein
Contact:

Post by HdB »

Usually, that means the same as "Anything without Microsoft in the title" :roll:

If you are comfortable with .NET, and it does everything you need, then use it.

By the way, what IDE are you using? Visual Studio? I like to use SharpDevelop. Its free and open source.
AMD Athlon 64 X2 4800+ s939 | Gecube 3870 OC edition
Image
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

I'm pretty good at C# but in reality .NET sucks.
C/C++ is easily the way to go for sheer programming power (granted, commercially something like java is preferable but meh).
Then theres Assembler, I'm rather partial to both MASM32 and FASM.
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

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
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

Yeah, C# and VB.NET are in the end the same thing, but god, C# is worlds more comfortable to use.
And there is nothing wrong with writing entire applications in nothing but assembler.
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

And there is nothing wrong with writing entire applications in nothing but assembler.
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?

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
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

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)
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

What type of apps / drivers do you write?
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
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

Currently, I'm busy writing a punkbuster bypass.
I write allot of security related applications as well.
I recently wrote a fairly decent packet editor that I was rather proud of.
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

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.
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
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

Yep :D

I've written a few anti-cheat bypasses... Its fun 8)
Post Reply