My textbox change reacts too quickly

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
Hi all. When I type an 11 into my textbox (in my userform), I believe that the moment I type the first 1, the "event" kicks in. Is there anyway that I can have the change even "wait" until I am finished typing in all the digits of my number?


Code:
Private Sub TextBox1_Change()
Dim prime As Integer, divisor As Integer, currentcol As Integer
Dim faccount As Integer, currentresidue As Long, currentfactor As Long
Dim i As Integer, j As Integer
prime = TextBox1.Value
TextBox2.Value = prime - 1
'Write divisors across and phi of the divisors across at the bottom
Spreadsheet1.Range("c2").Value = 1
Spreadsheet1.Range("c2").Font.Bold = True
currentcol = 3
Spreadsheet1.Cells(prime - 1 + 3, 2) = "phi(d):"
Spreadsheet1.Cells(prime - 1 + 3, 2).Font.Bold = True
Spreadsheet1.Cells(prime - 1 + 3, 2).HorizontalAlignment = xlRight
Spreadsheet1.Cells(prime - 1 + 3, 3) = 1
MsgBox "prime-1+3 right before bolding is " & prime - 1 + 3
Spreadsheet1.Cells(prime - 1 + 3, 3).Font.Bold = True
For i = 2 To prime - 1
    If Factor(i, prime - 1) Then
       currentcol = currentcol + 1
       Spreadsheet1.Cells(2, currentcol) = i
       Spreadsheet1.Cells(2, currentcol).Font.Bold = True
       Spreadsheet1.Cells(prime - 1 + 3, currentcol) = phi(i)
       Spreadsheet1.Cells(prime - 1 + 3, currentcol).Font.Bold = True
    Else
    End If
Next i
'Write residues down
Spreadsheet1.Range("b3").Value = 1
Spreadsheet1.Range("b3").Font.Bold = True
For i = 2 To prime - 1
 Spreadsheet1.Cells(i + 2, 2) = i
 Spreadsheet1.Cells(i + 2, 2).Font.Bold = True
Next

faccount = Factorcount(prime - 1)
currentcol = 3
For i = 0 To faccount - 1 ' columns
 For j = 1 To prime - 1       ' rows
 
 
  currentresidue = Spreadsheet1.Cells(j + 2, 2)
  currentfactor = Spreadsheet1.Cells(2, i + 3)
  
  Spreadsheet1.Cells(j + 2, currentcol + i) = PowerMOD(currentresidue, currentfactor, prime)
  If PR(currentresidue, prime) Then Spreadsheet1.Cells(j + 2, currentcol + i).Interior.Color = RGB(0, 255, 0) 'Green
 
 Next
Next
End Sub
 
Dear mortgageman,

Nearly 15 years after your question, I'm looking for a solution to the same problem you had in 2005. Googling - and trying - for some hours now.
My question: did you ever find solution to that problem or did you make a work-around for that? I would be very interested in it.
By the way, I agree to you that this must be a design bug of MS.... Unfortunately, it is nor repaired up to now

Best regards, Hans Troost
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
First of all: thanks for your reply to such an old post, Norie.

In my opnion the bug (see Mortgageman's post #17) is that the textcox_change event is not acting after a user typed in the changed value (possibly ending with something as an enter, tab) but it just acts nearly the same as a textbox_keydown event (except the special characters you can capture with the keydown).

Practical background of my problem: we (a food bank) will enter the data by barcode-scanning a customer card, and looking up customers record in an excel sheet. Works fine with the combination of barcode-scanner and textbox_change event.
But when preparing for scanner failures (which will occur earlier or later) and manual input of a 4 - 7 number digit (customer number) my programmed lookup function fires after the 1st typed in digit, popping up "not found" msgboxes for each digit, which it shouln't do: we have some 200 people in the line at a food bank, waiting for their food parcel and this behaviour (the message boxes) will lead to delays in the line.

Thanks to your reply I re-read the thread and readit better than I did yesterday: I now will give the textbox_keydown event a chance: both with manual input and barcode-scanner input (I can configure it to add an <enter> at the end).
 
Upvote 0
How exactly does the barcode scanner work with the textbox and how does your lookup function work?

Also, what exactly is happening when there's a scanner failure?
 
Upvote 0
Set it to wait until you have a requisite number of characters so minimum of 4 character length before triggering not found/lookups
 
Upvote 0
Hi Norie,

Is justs scans the card (example atttached) in the text box and then something like (but just started developemen this are only the first lines of development)

Klantenpas voorbeeld.png
and then (with the barcodescanner in the textbox_change event) which works!:

Dim wks As Worksheet
Set wks = ActiveSheet
wks.AutoFilterMode = False
wks.Range("A1").AutoFilter Field:=1, Criteria1:=txtVBnr.Value, VisibleDropDown:=False

End Sub

whenever the scanner fails the card-numer has to be entered manualy.

For you info: my communication will now and then slow down: my work at the food bank is as volunteer for automation and I use just 1 max 2 days a week, depending on available time.
 
Upvote 0
Hi Norie,

Just played around with both (very fast) barcode scanning or manually typing in the number. This works as a charm for me:


Private Sub txtVBnr_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode <> 13 Then Exit Sub
MsgBox "Both for typed in and scanned: start my programmed lookup function"
End Sub

Thanks again for willing to support me and for triggering my re-read of this thread (which helped me to find this solution)
 
Upvote 0

Forum statistics

Threads
1,224,713
Messages
6,180,520
Members
452,986
Latest member
zenki1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top