Как я считаю правильное время, когда дата меняется VB
я делаю программу для своей работы, чтобы рассчитать часы, отработанные материалом, у меня есть 2 текстовых поля для каждого дня недели, одно для того, чтобы поставить время начала и следующее Время окончания, я заставляю его работать без проблем, пока не поставлю время окончания до 24: 00 или 24: 30
или 00: 00 или 00: 30
Что я уже пробовал:
Dim a As String Dim t1 As DateTime '= DateTime.Parse(stathisa.Text) Dim t2 As DateTime '= DateTime.Parse(stathis1.Text) Dim t3 As DateTime '= DateTime.Parse(stathisb.Text) Dim t4 As DateTime '= DateTime.Parse(stathis2.Text) Dim t5 As DateTime '= DateTime.Parse(stathisc.Text) Dim t6 As DateTime '= DateTime.Parse(stathis3.Text) Dim t7 As DateTime '= DateTime.Parse(stathisd.Text) Dim t8 As DateTime '= DateTime.Parse(stathis4.Text) Dim t9 As DateTime '= DateTime.Parse(stathise.Text) Dim t10 As DateTime '= DateTime.Parse(stathis5.Text) Dim t11 As DateTime '= DateTime.Parse(stathisf.Text) Dim t12 As DateTime '= DateTime.Parse(stathis6.Text) Dim t13 As DateTime '= DateTime.Parse(stathisg.Text) Dim t14 As DateTime '= DateTime.Parse(stathis7.Text) If stathisa.Text = "OFF" Or stathis1.Text = "OFF" Then stathis1.Text = "OFF" stathisa.Text = "OFF" End If If stathisb.Text = "OFF" Or stathis2.Text = "OFF" Then stathis2.Text = "OFF" stathisb.Text = "OFF" End If If stathisc.Text = "OFF" Or stathis3.Text = "OFF" Then stathis3.Text = "OFF" stathisc.Text = "OFF" End If If stathisd.Text = "OFF" Or stathis4.Text = "OFF" Then stathis4.Text = "OFF" stathisd.Text = "OFF" End If If stathise.Text = "OFF" Or stathis5.Text = "OFF" Then stathis5.Text = "OFF" stathise.Text = "OFF" End If If stathisf.Text = "OFF" Or stathis6.Text = "OFF" Then stathis6.Text = "OFF" stathisf.Text = "OFF" '' End If If stathisg.Text = "OFF" Or stathis7.Text = "OFF" Then stathis7.Text = "OFF" stathisg.Text = "OFF" End If If stathisa.Text = "HOLIDAYS" Or stathis1.Text = "HOLIDAYS" Then stathis1.Text = "HOLIDAYS" stathisa.Text = "HOLIDAYS" End If If stathisb.Text = "HOLIDAYS" Or stathis2.Text = "HOLIDAYS" Then stathis2.Text = "HOLIDAYS" stathisb.Text = "HOLIDAYS" End If If stathisc.Text = "HOLIDAYS" Or stathis3.Text = "HOLIDAYS" Then stathis3.Text = "HOLIDAYS" stathisc.Text = "HOLIDAYS" End If If stathisd.Text = "HOLIDAYS" Or stathis4.Text = "HOLIDAYS" Then stathis4.Text = "HOLIDAYS" stathisd.Text = "HOLIDAYS" End If If stathise.Text = "HOLIDAYS" Or stathis5.Text = "HOLIDAYS" Then stathis5.Text = "HOLIDAYS" stathise.Text = "HOLIDAYS" End If If stathisf.Text = "HOLIDAYS" Or stathis6.Text = "HOLIDAYS" Then stathis6.Text = "HOLIDAYS" stathisf.Text = "HOLIDAYS" '' End If If stathisg.Text = "HOLIDAYS" Or stathis7.Text = "HOLIDAYS" Then stathis7.Text = "HOLIDAYS" stathisg.Text = "HOLIDAYS" End If If stathisa.SelectedIndex = -1 Or stathis1.SelectedIndex = -1 Then stathis1.SelectedIndex = -1 stathisa.SelectedIndex = -1 End If If stathisb.SelectedIndex = -1 Or stathis2.SelectedIndex = -1 Then stathis2.SelectedIndex = -1 stathisb.SelectedIndex = -1 End If If stathisc.SelectedIndex = -1 Or stathis3.SelectedIndex = -1 Then stathis3.SelectedIndex = -1 stathisc.SelectedIndex = -1 End If If stathisd.SelectedIndex = -1 Or stathis4.SelectedIndex = -1 Then stathis4.SelectedIndex = -1 stathisd.SelectedIndex = -1 End If If stathise.SelectedIndex = -1 Or stathis5.SelectedIndex = -1 Then stathis5.SelectedIndex = -1 stathise.SelectedIndex = -1 End If If stathisf.SelectedIndex = -1 Or stathis6.SelectedIndex = -1 Then stathis6.SelectedIndex = -1 stathisf.SelectedIndex = -1 '' End If If stathisg.SelectedIndex = -1 Or stathis7.SelectedIndex = -1 Then stathis7.SelectedIndex = -1 stathisg.SelectedIndex = -1 End If If stathisa.Text.Contains("OFF") = False Or stathisa.Text.Contains("HOLIDAYS") = False Or stathisa.Text = vbNullString = False Or stathis1.Text.Contains("OFF") = False Or stathis1.Text.Contains("HOLIDAYS") = False Or stathis1.Text = vbNullString Then Try t1 = DateTime.Parse(stathisa.Text) t2 = DateTime.Parse(stathis1.Text) Catch ex As Exception End Try Else t1 = vbNullString t2 = vbNullString End If If stathisb.Text.Contains("OFF") = False Or stathisb.Text.Contains("HOLIDAYS") = False Or stathisb.Text = vbNullString = False Or stathis2.Text.Contains("OFF") = False Or stathis2.Text.Contains("HOLIDAYS") = False Or stathis2.Text = vbNullString Then Try t3 = DateTime.Parse(stathisb.Text) t4 = DateTime.Parse(stathis2.Text) Catch ex As Exception End Try Else t3 = vbNullString t4 = vbNullString End If If stathisc.Text.Contains("OFF") = False Or stathisc.Text.Contains("HOLIDAYS") = False Or stathisc.Text = vbNullString = False Or stathis3.Text.Contains("OFF") = False Or stathis3.Text.Contains("HOLIDAYS") = False Or stathis3.Text = vbNullString Then Try t5 = DateTime.Parse(stathisc.Text) t6 = DateTime.Parse(stathis3.Text) Catch ex As Exception End Try Else t5 = vbNullString t6 = vbNullString End If If stathisd.Text.Contains("OFF") = False Or stathisd.Text.Contains("HOLIDAYS") = False Or stathisd.Text = vbNullString = False Or stathis4.Text.Contains("OFF") = False Or stathis4.Text.Contains("HOLIDAYS") = False Or stathis4.Text = vbNullString Then Try t7 = DateTime.Parse(stathisd.Text) t8 = DateTime.Parse(stathis4.Text) Catch ex As Exception End Try Else t7 = vbNullString t8 = vbNullString End If If stathise.Text.Contains("OFF") = False Or stathise.Text.Contains("HOLIDAYS") = False Or stathise.Text = vbNullString = False Or stathis5.Text.Contains("OFF") = False Or stathis5.Text.Contains("HOLIDAYS") = False Or stathis5.Text = vbNullString Then Try t9 = DateTime.Parse(stathise.Text) t10 = DateTime.Parse(stathis5.Text) Catch ex As Exception End Try Else t9 = vbNullString t10 = vbNullString End If If stathisf.Text.Contains("OFF") = False Or stathisf.Text.Contains("HOLIDAYS") = False Or stathisf.Text = vbNullString = False Or stathisf.Text.Contains("OFF") = False Or stathisf.Text.Contains("HOLIDAYS") = False Or stathisf.Text = vbNullString Then Try t11 = DateTime.Parse(stathisf.Text) t12 = DateTime.Parse(stathis6.Text) Catch ex As Exception End Try Else t11 = vbNullString t12 = vbNullString End If If stathisg.Text.Contains("OFF") = False Or stathisg.Text.Contains("HOLIDAYS") = False Or stathisg.Text = vbNullString = False Or stathis7.Text.Contains("OFF") = False Or stathis7.Text.Contains("HOLIDAYS") = False Or stathis7.Text = vbNullString Then Try t13 = DateTime.Parse(stathisg.Text) t14 = DateTime.Parse(stathis7.Text) Catch ex As Exception End Try Else t13 = vbNullString t14 = vbNullString End If Dim ts As TimeSpan = ((t1.Subtract(t2)) + (t3.Subtract(t4) + (t5.Subtract(t6) + (t7.Subtract(t8) + (t9.Subtract(t10) + (t11.Subtract(t12) + (t13.Subtract(t14)))))))) a = (ts).Hours.ToString("00") & ":" & ts.Minutes.ToString("00") a = Abs(ts.TotalHours) TextBox1.Text = a If a > 42 Then TextBox1.ReadOnly = False TextBox1.ForeColor = Color.Red MessageBox.Show("Maximum Hours Exceeded") Else TextBox1.ForeColor = Color.Black TextBox1.ReadOnly = True End If
NotPolitcallyCorrect
Научитесь использовать отладчик для отладки кода.
Richard MacCutchan
Убедитесь, что ваши объекты DateTime содержат правильное значение дня, когда время позже 23:59.
Member 10289378
Ричард спасибо текущая проблема решена я просто делаю это, чтобы добавить день(1) к каждой переменной endtime dattime, если условие выполнено и работает гладко :)