Visual Basic Time Converter

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.  
  25.     Dim lastEdited As Integer = 0
  26.     Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  27.         lastEdited = 0
  28.     End Sub
  29.  
  30.     Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
  31.         lastEdited = 1
  32.     End Sub
  33.  
  34.     Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
  35.         lastEdited = 2
  36.     End Sub
  37.  
  38.     Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
  39.         lastEdited = 3
  40.     End Sub
  41. End Class

Comments

I need help to make a code that converts money to change

Add new comment