Making a timer application?

Soldato
Joined
30 Jul 2004
Posts
10,572
Location
East Sussex, UK
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?
Will be using VB for it, C++

Thanks guys!
 
Heres a pretty crude way of just comparing two system clock values. Includes date and time. You can pass in your timestamp (providing its in the same format as the system clock) for comparison with the datetime obtained when stop is pressed.

Code:
 #pragma once

namespace timer1 {
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
		}
	protected:
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::DateTime firstDateTime;
	private: System::DateTime secondDateTime;
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::ComponentModel::IContainer^  components;
#pragma region Windows Form Designer generated code
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			this->button1->Location = System::Drawing::Point(24, 12);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Start";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::startTimer);
			this->button2->Location = System::Drawing::Point(24, 42);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(75, 23);
			this->button2->TabIndex = 1;
			this->button2->Text = L"Stop";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::stopTimer);
			this->textBox1->Location = System::Drawing::Point(12, 71);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(100, 20);
			this->textBox1->TabIndex = 2;
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(288, 237);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);
			this->PerformLayout();
		}
#pragma endregion

	private: System::Void startTimer(System::Object^  sender, System::EventArgs^  e) {
				 firstDateTime = DateTime::Now::get();
			 }

	private: System::Void stopTimer(System::Object^  sender, System::EventArgs^  e) {
				 secondDateTime = DateTime::Now::get();
				 this->textBox1->Text = Convert::ToString(secondDateTime.Subtract(firstDateTime));
			 }
};
}
 
Back
Top Bottom