一个textbox,我想获取从输入第一个字符开始到回车总共花了多少时间,如何能够实现?

解决方案 »

  1.   

    change事件记录最早的时间keypress事件 if 回车 记录时间时间相减
      

  2.   


    Option ExplicitPrivate Sub Text1_KeyPress(KeyAscii As Integer)
        Static lngTime As Long
        If lngTime = 0 Then
            lngTime = Timer
            Debug.Print "开始录入"
        ElseIf KeyAscii = 13 Then
            Debug.Print "停止录入,时间:" + CStr(Timer - lngTime) + "秒"
            lngTime = 0
        End If
        
    End Sub
      

  3.   

    Option Explicit
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      Static lngTime  As Single '这个最好是单精度浮点数
      If lngTime = 0 Then
        lngTime = Timer
        Debug.Print "开始录入"
      ElseIf KeyAscii = 13 Then
        Debug.Print "停止录入,时间:" + CStr(Timer - lngTime) + "秒"
        lngTime = 0
      End If
    End Sub