• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Visual Basic Time Converter

MAQUINI

Marketplace Revenue Analyst
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
79
Likes
75
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
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)...

  1. Dim

    lastEdited As

    Integer

    = 0
  2. Private

    Sub

    TextBox1_TextChanged(sender As

    Object

    , e As

    EventArgs) Handles TextBox1.TextChanged
  3. lastEdited = 0
  4. End

    Sub
  5. Private

    Sub

    TextBox2_TextChanged(sender As

    Object

    , e As

    EventArgs) Handles TextBox2.TextChanged
  6. lastEdited = 1
  7. End

    Sub
  8. Private

    Sub

    TextBox3_TextChanged(sender As

    Object

    , e As

    EventArgs) Handles TextBox3.TextChanged
  9. lastEdited = 2
  10. End

    Sub
  11. Private

    Sub

    TextBox4_TextChanged(sender As

    Object

    , e As

    EventArgs) Handles TextBox4.TextChanged
  12. lastEdited = 3
  13. 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.

  1. Private

    Sub

    Button1_Click(sender As

    Object

    , e As

    EventArgs) Handles Button1.Click
  2. Dim

    nowHour As

    Integer

    = My.Computer.Clock.LocalTime.Hour
  3. Dim

    nowMinute As

    Integer

    = My.Computer.Clock.LocalTime.Minute
  4. Dim

    nowSecond As

    Integer

    = My.Computer.Clock.LocalTime.Second
  5. If

    (lastEdited = 0) Then
  6. TextBox2.Text = TextBox1.Text * 60
  7. TextBox3.Text = TextBox1.Text * 60 * 60
  8. TextBox4.Text = TextBox3.Text * 1000
  9. ElseIf

    (lastEdited = 1) Then
  10. TextBox1.Text = TextBox2.Text / 60
  11. TextBox3.Text = TextBox1.Text * 60 * 60
  12. TextBox4.Text = TextBox3.Text * 1000
  13. ElseIf

    (lastEdited = 2) Then
  14. TextBox1.Text = TextBox3.Text / 60 / 60
  15. TextBox2.Text = TextBox1.Text * 60
  16. TextBox4.Text = TextBox3.Text * 1000
  17. ElseIf

    (lastEdited = 3) Then
  18. TextBox3.Text = TextBox4.Text / 1000
  19. TextBox2.Text = TextBox3.Text / 60
  20. TextBox1.Text = TextBox2.Text / 60
  21. End

    If
  22. End

    Sub

Project Complete!
That's it! Below is the full source code and download to the project files...

  1. Public

    Class Form1
  2. Private

    Sub

    Button1_Click(sender As

    Object

    , e As

    EventArgs) Handles Button1.Click
  3. Dim

    nowHour As

    Integer

    = My.Computer.Clock.LocalTime.Hour
  4. Dim

    nowMinute As

    Integer

    = My.Computer.Clock.LocalTime.Minute
  5. Dim

    nowSecond As

    Integer

    = My.Computer.Clock.LocalTime.Second
  6. If

    (lastEdited = 0) Then
  7. TextBox2.Text = TextBox1.Text * 60
  8. TextBox3.Text = TextBox1.Text * 60 * 60
  9. TextBox4.Text = TextBox3.Text * 1000
  10. ElseIf

    (lastEdited = 1) Then
  11. TextBox1.Text = TextBox2.Text / 60
  12. TextBox3.Text = TextBox1.Text * 60 * 60
  13. TextBox4.Text = TextBox3.Text * 1000
  14. ElseIf

    (lastEdited = 2) Then
  15. TextBox1.Text = TextBox3.Text / 60 / 60
  16. TextBox2.Text = TextBox1.Text * 60
  17. TextBox4.Text = TextBox3.Text * 1000
  18. ElseIf

    (lastEdited = 3) Then
  19. TextBox3.Text = TextBox4.Text / 1000
  20. TextBox2.Text = TextBox3.Text / 60
  21. TextBox1.Text = TextBox2.Text / 60
  22. End

    If
  23. End

    Sub

  24. Dim

    lastEdited As

    Integer

    = 0
  25. Private

    Sub

    TextBox1_TextChanged(sender As

    Object

    , e As

    EventArgs) Handles TextBox1.TextChanged
  26. lastEdited = 0
  27. End

    Sub

  28. Private

    Sub

    TextBox2_TextChanged(sender As

    Object

    , e As

    EventArgs) Handles TextBox2.TextChanged
  29. lastEdited = 1
  30. End

    Sub

  31. Private

    Sub

    TextBox3_TextChanged(sender As

    Object

    , e As

    EventArgs) Handles TextBox3.TextChanged
  32. lastEdited = 2
  33. End

    Sub

  34. Private

    Sub

    TextBox4_TextChanged(sender As

    Object

    , e As

    EventArgs) Handles TextBox4.TextChanged
  35. lastEdited = 3
  36. End

    Sub
  37. End

    Class


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,503

355,786

355,794

Top