我正在通过文本框从USERFORM中输入两个“ CheckIn Time(hh:mm
格式)”和“ Checkout Time(hh:mm
格式)”,并试图在第三个Text Box({ {1}}格式),显示签入和签出之间的差异。
为此,我使用hh:mm
方法。
但是我遇到错误
“运行时13:类型不匹配”。
我是VBA的新手,自2个星期以来,我在这方面一直陷于困境。请帮忙。
我尝试更改DATA类型,但没有得到任何肯定的结果。
Call Sub procedure
想要所需的结果:Private Sub CHKIN_Change() 'Calling GetTime
Call GetTime
End Sub
Private Sub CHKOUT_Change() 'Calling GetTime
Call GetTime
End Sub
Private Sub TOTALHRS_Change() 'Calling GetTime
Call GetTime
End Sub
'below Calculating difference b/t Checkin & Checkout, displaying in "TOTALHRS" textbox
Sub GetTime()
Dim Time1, Time2, TotalTime As Date
Time1 = CHKIN.Text
Time2 = CHKOUT.Text
TotalTime = DateDiff("s", Time1, Time2)
TotalTime = Totalhour / 86400
TOTALHRS.Text = Format(Totalhour, "hh:mm")
End Sub
'Using below code to convert checkin and checkout input in hh:mm format.
Private Sub CHKIN_AfterUpdate()
Dim tDate As Date
Dim tString As String
With CHKIN
'Check if user put in a colon or not
If InStr(1, .Value, ":", vbTextCompare) = 0 Then
'If not, make string 4 digits and insert colon
tString = Format(.Value, "0000")
tDate = TimeSerial(Left(tString, 2), Right(tString, 2), 0)
CHKIN.Value = Format(tDate, "HH:MM")
Else
'Otherwise, take value as given
.Value = Format(.Value, "hh:mm")
End If
End With
Exit Sub
End Sub
-checkout
= checkin
示例:hh:mm
-23:20
= 9:35