MAQUINI
Marketplace Revenue Analyst
LEVEL 2
1000 XP
Introduction:
Welcome to a tutorial on a time conversion program in Visual Basic.
Steps of Creation:
Step 1:
First lets make a new form with four textboxes and a button:
- Textbox1 : Hours
- Textbox2 : Minutes
- Textbox3 : Seconds
- Textbox4 : Milliseconds
- Button1 : Convert
Step 2:
Now lets make a way to check which textbox was last edited (What to convert from)...
Step 3:
And the final step is to simply change the text accordingly whenever the convert button is clicked. Simple sums. Simple code.
Project Complete!
That's it! Below is the full source code and download to the project files...
Download
Welcome to a tutorial on a time conversion program in Visual Basic.
Steps of Creation:
Step 1:
First lets make a new form with four textboxes and a button:
- Textbox1 : Hours
- Textbox2 : Minutes
- Textbox3 : Seconds
- Textbox4 : Milliseconds
- Button1 : Convert
Step 2:
Now lets make a way to check which textbox was last edited (What to convert from)...
- Dim
lastEdited As
Integer
= 0
- Private
Sub
TextBox1_TextChanged(sender As
Object
, e As
EventArgs) Handles TextBox1.TextChanged
- lastEdited = 0
- End
Sub
- Private
Sub
TextBox2_TextChanged(sender As
Object
, e As
EventArgs) Handles TextBox2.TextChanged
- lastEdited = 1
- End
Sub
- Private
Sub
TextBox3_TextChanged(sender As
Object
, e As
EventArgs) Handles TextBox3.TextChanged
- lastEdited = 2
- End
Sub
- Private
Sub
TextBox4_TextChanged(sender As
Object
, e As
EventArgs) Handles TextBox4.TextChanged
- lastEdited = 3
- End
Sub
Step 3:
And the final step is to simply change the text accordingly whenever the convert button is clicked. Simple sums. Simple code.
- Private
Sub
Button1_Click(sender As
Object
, e As
EventArgs) Handles Button1.Click
- Dim
nowHour As
Integer
= My.Computer.Clock.LocalTime.Hour
- Dim
nowMinute As
Integer
= My.Computer.Clock.LocalTime.Minute
- Dim
nowSecond As
Integer
= My.Computer.Clock.LocalTime.Second
- If
(lastEdited = 0) Then
- TextBox2.Text = TextBox1.Text * 60
- TextBox3.Text = TextBox1.Text * 60 * 60
- TextBox4.Text = TextBox3.Text * 1000
- ElseIf
(lastEdited = 1) Then
- TextBox1.Text = TextBox2.Text / 60
- TextBox3.Text = TextBox1.Text * 60 * 60
- TextBox4.Text = TextBox3.Text * 1000
- ElseIf
(lastEdited = 2) Then
- TextBox1.Text = TextBox3.Text / 60 / 60
- TextBox2.Text = TextBox1.Text * 60
- TextBox4.Text = TextBox3.Text * 1000
- ElseIf
(lastEdited = 3) Then
- TextBox3.Text = TextBox4.Text / 1000
- TextBox2.Text = TextBox3.Text / 60
- TextBox1.Text = TextBox2.Text / 60
- End
If
- End
Sub
Project Complete!
That's it! Below is the full source code and download to the project files...
- Public
Class Form1
- Private
Sub
Button1_Click(sender As
Object
, e As
EventArgs) Handles Button1.Click
- Dim
nowHour As
Integer
= My.Computer.Clock.LocalTime.Hour
- Dim
nowMinute As
Integer
= My.Computer.Clock.LocalTime.Minute
- Dim
nowSecond As
Integer
= My.Computer.Clock.LocalTime.Second
- If
(lastEdited = 0) Then
- TextBox2.Text = TextBox1.Text * 60
- TextBox3.Text = TextBox1.Text * 60 * 60
- TextBox4.Text = TextBox3.Text * 1000
- ElseIf
(lastEdited = 1) Then
- TextBox1.Text = TextBox2.Text / 60
- TextBox3.Text = TextBox1.Text * 60 * 60
- TextBox4.Text = TextBox3.Text * 1000
- ElseIf
(lastEdited = 2) Then
- TextBox1.Text = TextBox3.Text / 60 / 60
- TextBox2.Text = TextBox1.Text * 60
- TextBox4.Text = TextBox3.Text * 1000
- ElseIf
(lastEdited = 3) Then
- TextBox3.Text = TextBox4.Text / 1000
- TextBox2.Text = TextBox3.Text / 60
- TextBox1.Text = TextBox2.Text / 60
- End
If
- End
Sub
- Dim
lastEdited As
Integer
= 0
- Private
Sub
TextBox1_TextChanged(sender As
Object
, e As
EventArgs) Handles TextBox1.TextChanged
- lastEdited = 0
- End
Sub
- Private
Sub
TextBox2_TextChanged(sender As
Object
, e As
EventArgs) Handles TextBox2.TextChanged
- lastEdited = 1
- End
Sub
- Private
Sub
TextBox3_TextChanged(sender As
Object
, e As
EventArgs) Handles TextBox3.TextChanged
- lastEdited = 2
- End
Sub
- Private
Sub
TextBox4_TextChanged(sender As
Object
, e As
EventArgs) Handles TextBox4.TextChanged
- lastEdited = 3
- End
Sub
- End
Class
Download
You must upgrade your account or reply in the thread to view the hidden content.