To check keychangeof textbox  after a predifined time.

Posted on 2006-05-06
Last Modified: 2010-05-01
  Quesion in one sentence - how to  restrict checking of  textbox keychange at  a given interval ?

 This is a basic appln and the user starts entering a value to a textbox.
 Is there a way in VB6 to see anything is keyed in for a predefined time (20sec).
  If nothing is keyed in ,then call a procedure.

 For eg.
##   The user starts entering 1234 and then waits for this predefined time(20sec).
        Then the procedure should be called passing the value 1234.
 ##  But if the user enters 1234 waits 10 sec and then keeps typing 5678
        Then 10 sec waiting should be ignored and  the procedure should be called with a value 12345678.

How to do this?
Question by:sgs1970
    LVL 4

    Expert Comment

    Use a timer, and activate it using the keypress event for the textbox.  Just make sure you only activate it once.  Make a boolean or something and check it to see if you have activated the timer.
    LVL 17

    Accepted Solution

    Dim idle As Integer

    Private Sub Command1_Click()
    MsgBox Text1
    End Sub

    Private Sub Form_Load()
    idle = 0
    Timer1.Enabled = False
    Timer1.Interval = 1000
    End Sub

    Private Sub Text1_Change()
    idle = 0
    If Len(Text1) = 8 Then
    Call Command1_Click
    ElseIf Text1 <> "" Then
    Timer1.Enabled = True
    Timer1.Enabled = False
    End If
    End Sub

    Private Sub Timer1_Timer()
    idle = idle + 1
    Form1.Caption = idle & " seconds"
    If idle = 20 Then
    Call Command1_Click
    idle = 0
    Timer1.Enabled = False
    End If
    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now