Zero Escape
New member
- Joined
- Mar 3, 2015
- Messages
- 1
- Programming Experience
- Beginner
Hello, I am very new to this whole vb universe. But I am trying to make a program for my teacher to use to calculate the amount of hours a student has been signed in each day.
The goal of the program is to find the time between two textbox values (hh:mm) and add the answer into another textbox.
This is how how I have done that:
The timespan between the two datetimes is then added to a master list of times so they can all be later added to create a total.
This is my entire project so far and I'm hoping you guys here can tell me how to properly add the time spans in the masterlist. Currently this will work but will return "12:00" in label42 and I don't know why. Just ask if I need to further elaborate on this. Here is my code:
Also if anyone could tell me how to clean up my code it would be greatly appreciated. I'm eager to learn
The goal of the program is to find the time between two textbox values (hh:mm) and add the answer into another textbox.
This is how how I have done that:
VB.NET:
Dim time1 As Date
Dim time2 As Date
Dim span1 As TimeSpan
time1 = Convert.ToDateTime(TextBox1.Text)
time2 = Convert.ToDateTime(TextBox2.Text)
span1 = time2.Subtract(time1)
Label5.Text = span1.ToString("hh\:mm")
The timespan between the two datetimes is then added to a master list of times so they can all be later added to create a total.
This is my entire project so far and I'm hoping you guys here can tell me how to properly add the time spans in the masterlist. Currently this will work but will return "12:00" in label42 and I don't know why. Just ask if I need to further elaborate on this. Here is my code:
VB.NET:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Label5.Text = ""
Label42.Text = ""
Label43.Text = ""
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
Label5.Text = ""
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim time1 As Date
Dim time2 As Date
Dim span1 As TimeSpan
time1 = Convert.ToDateTime(TextBox1.Text)
time2 = Convert.ToDateTime(TextBox2.Text)
span1 = time2.Subtract(time1)
Label5.Text = span1.ToString("hh\:mm")
If CheckBox1.Checked Then
If TextBox4.Text = "" And TextBox3.Text = "" Then
TextBox4.Text = TextBox1.Text
TextBox3.Text = TextBox2.Text
TextBox5.Text = span1.ToString("hh\:mm")
ElseIf TextBox7.Text = "" And TextBox8.Text = "" Then
TextBox7.Text = TextBox1.Text
TextBox8.Text = TextBox2.Text
TextBox6.Text = span1.ToString("hh\:mm")
ElseIf TextBox10.Text = "" And TextBox11.Text = "" Then
TextBox10.Text = TextBox1.Text
TextBox11.Text = TextBox2.Text
TextBox9.Text = span1.ToString("hh\:mm")
ElseIf TextBox19.Text = "" And TextBox20.Text = "" Then
TextBox19.Text = TextBox1.Text
TextBox20.Text = TextBox2.Text
TextBox18.Text = span1.ToString("hh\:mm")
ElseIf TextBox16.Text = "" And TextBox17.Text = "" Then
TextBox16.Text = TextBox1.Text
TextBox17.Text = TextBox2.Text
TextBox15.Text = span1.ToString("hh\:mm")
ElseIf TextBox13.Text = "" And TextBox14.Text = "" Then
TextBox13.Text = TextBox1.Text
TextBox14.Text = TextBox2.Text
TextBox12.Text = span1.ToString("hh\:mm")
ElseIf TextBox28.Text = "" And TextBox29.Text = "" Then
TextBox28.Text = TextBox1.Text
TextBox29.Text = TextBox2.Text
TextBox27.Text = span1.ToString("hh\:mm")
ElseIf TextBox25.Text = "" And TextBox26.Text = "" Then
TextBox25.Text = TextBox1.Text
TextBox26.Text = TextBox2.Text
TextBox24.Text = span1.ToString("hh\:mm")
ElseIf TextBox22.Text = "" And TextBox23.Text = "" Then
TextBox22.Text = TextBox1.Text
TextBox23.Text = TextBox2.Text
TextBox21.Text = span1.ToString("hh\:mm")
ElseIf TextBox37.Text = "" And TextBox38.Text = "" Then
TextBox37.Text = TextBox1.Text
TextBox38.Text = TextBox2.Text
TextBox36.Text = span1.ToString("hh\:mm")
ElseIf TextBox34.Text = "" And TextBox35.Text = "" Then
TextBox34.Text = TextBox1.Text
TextBox35.Text = TextBox2.Text
TextBox33.Text = span1.ToString("hh\:mm")
ElseIf TextBox31.Text = "" And TextBox32.Text = "" Then
TextBox31.Text = TextBox1.Text
TextBox32.Text = TextBox2.Text
TextBox30.Text = span1.ToString("hh\:mm")
ElseIf TextBox46.Text = "" And TextBox47.Text = "" Then
TextBox46.Text = TextBox1.Text
TextBox47.Text = TextBox2.Text
TextBox45.Text = span1.ToString("hh\:mm")
ElseIf TextBox43.Text = "" And TextBox44.Text = "" Then
TextBox43.Text = TextBox1.Text
TextBox44.Text = TextBox2.Text
TextBox42.Text = span1.ToString("hh\:mm")
ElseIf TextBox40.Text = "" And TextBox41.Text = "" Then
TextBox40.Text = TextBox1.Text
TextBox41.Text = TextBox2.Text
TextBox39.Text = span1.ToString("hh\:mm")
Else : MessageBox.Show("Clear the totals list to continue calculatimg")
End If
End If
End Sub
Private Sub Label1_Click(sender As System.Object, e As System.EventArgs) Handles Label1.Click
MessageBox.Show("Time Sheet Calculator" & vbCrLf & "Version: 1.0.0" & vbCrLf & "Created by: Gary Byrne")
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox13.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
TextBox16.Text = ""
TextBox17.Text = ""
TextBox18.Text = ""
TextBox19.Text = ""
TextBox20.Text = ""
TextBox21.Text = ""
TextBox22.Text = ""
TextBox23.Text = ""
TextBox24.Text = ""
TextBox25.Text = ""
TextBox26.Text = ""
TextBox27.Text = ""
TextBox28.Text = ""
TextBox29.Text = ""
TextBox30.Text = ""
TextBox31.Text = ""
TextBox32.Text = ""
TextBox33.Text = ""
TextBox34.Text = ""
TextBox35.Text = ""
TextBox36.Text = ""
TextBox37.Text = ""
TextBox38.Text = ""
TextBox39.Text = ""
TextBox40.Text = ""
TextBox41.Text = ""
TextBox42.Text = ""
TextBox43.Text = ""
TextBox44.Text = ""
TextBox45.Text = ""
TextBox46.Text = ""
TextBox47.Text = ""
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Dim total1 As Date
Dim total2 As Date
Dim total3 As Date
Dim total4 As Date
Dim total5 As Date
Dim total6 As Date
Dim total7 As Date
Dim total8 As Date
Dim total9 As Date
Dim total10 As Date
Dim total11 As Date
Dim total12 As Date
Dim total13 As Date
Dim total14 As Date
Dim total15 As Date
Dim tstotal As Date
If TextBox5.Text = "" Then
Else
total1 = Convert.ToDateTime(TextBox5.Text)
End If
If TextBox6.Text = "" Then
Else
total2 = Convert.ToDateTime(TextBox6.Text)
End If
If TextBox9.Text = "" Then
Else
total3 = Convert.ToDateTime(TextBox9.Text)
End If
If TextBox18.Text = "" Then
Else
total4 = Convert.ToDateTime(TextBox18.Text)
End If
If TextBox15.Text = "" Then
Else
total5 = Convert.ToDateTime(TextBox15.Text)
End If
If TextBox12.Text = "" Then
Else
total6 = Convert.ToDateTime(TextBox12.Text)
End If
If TextBox27.Text = "" Then
Else
total7 = Convert.ToDateTime(TextBox27.Text)
End If
If TextBox24.Text = "" Then
Else
total8 = Convert.ToDateTime(TextBox24.Text)
End If
If TextBox21.Text = "" Then
Else
total9 = Convert.ToDateTime(TextBox21.Text)
End If
If TextBox36.Text = "" Then
Else
total10 = Convert.ToDateTime(TextBox36.Text)
End If
If TextBox33.Text = "" Then
Else
total11 = Convert.ToDateTime(TextBox33.Text)
End If
If TextBox30.Text = "" Then
Else
total12 = Convert.ToDateTime(TextBox30.Text)
End If
If TextBox45.Text = "" Then
Else
total13 = Convert.ToDateTime(TextBox45.Text)
End If
If TextBox42.Text = "" Then
Else
total14 = Convert.ToDateTime(TextBox42.Text)
End If
If TextBox39.Text = "" Then
Else
total15 = Convert.ToDateTime(TextBox39.Text)
End If
'this is where i want to add all the totals (total1 through total15)
tstotal = Date.FromOADate(Val(total1) + Val(total2))
Label42.Text = tstotal.ToString("hh\:mm")
End Sub
End Class
Also if anyone could tell me how to clean up my code it would be greatly appreciated. I'm eager to learn