【发布时间】:2018-12-20 12:38:12
【问题描述】:
我有一个用户窗体,其中有两个文本框,用户在其中输入停机时间并将其放入列表框中,现在在同一个用户窗体中,我有另一个禁用的文本框,显示这两个文本的所有数字的总和(以分钟为单位)有时,代码运行良好,问题在于例如:用户在“txtTStart”文本框中输入 2300,在“txtTEnd”中输入 0010,它会带来 -1370 数字。我的问题是我怎样才能得到这个方法的正确总和。
Private Sub cmdNext_Click()
Dim x As Integer
Dim totaldt As Double
Dim r As Long
Dim tdt As Double
Dim tdtt As Double
If Trim(Me.txtTStart.Value) = "" Then
Me.txtTStart.SetFocus
MsgBox "Please Enter Time Start"
Exit Sub
End If
If Trim(Me.txtTEnd.Value) = "" Then
Me.txtTEnd.SetFocus
MsgBox "Please Enter Time End"
Exit Sub
End If
If Trim(Me.cmbCode.Value) = "" Then
Me.cmbCode.SetFocus
MsgBox "Please Enter Downtime Code"
Exit Sub
End If
If Trim(Me.txtDesc.Value) = "" Then
Me.txtDesc.SetFocus
MsgBox "Please Enter Downtime Description"
Exit Sub
End If
If Trim(Me.txtDesc.Value) = "INVALID DOWNTIME CODE" Then
Me.txtDesc.SetFocus
MsgBox "Please Insert Valid Downtime Code"
Exit Sub
End If
tdt = Format((CDate(txtTEnd.Value) - CDate(txtTStart.Value)) * 1440)
tdtt = Round(tdt)
x = lstDes.ListCount
With lstDes
.AddItem
.List(x, 0) = txtTStart.Value
.List(x, 1) = txtTEnd.Value
.List(x, 2) = tdtt
.List(x, 3) = cmbCode.Value
.List(x, 4) = txtDesc.Value
End With
totaldt = 0
With lstDes
For r = 0 To .ListCount - 1
totaldt = totaldt + .List(r, 2)
Next r
End With
txtDT.Value = totaldt
Me.txtTStart.Value = ""
Me.txtTEnd.Value = ""
'Me.txtTot.Value = ""
Me.cmbCode.Value = ""
Me.txtDesc.Value = ""
End Sub
【问题讨论】: