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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Well that works - sort of. It requires me (or the user) to click somewhere else outside of the (ONLY) input box. Is there any other solution?

Gene
 
Upvote 0
*BMP* Seriously? There is no good way to enter a 2 digit number into a userform?????

Gene
 
Upvote 0
Check the length of what's in the texbox.

If it's less than the required length exit the sub.

Of course that will only work if there is a set length.
 
Upvote 0
*BMP* Seriously? There is no good way to enter a 2 digit number into a userform?????

Gene
 
Upvote 0
Check the length of what's in the texbox.

If it's less than the required length exit the sub.

Of course that will only work if there is a set length.

No, because they might correctly put in a single digit number. I am frankly amazed at this. This can't be the first case of someone wanting numeric input in a userform.

Gene
 
Upvote 0
Gene

Sorry, you've lost me.

How is VBA to know when you've typed in the correct no of digits?

What is the correct no of digits?

Why wouldn't checking the length work?
 
Upvote 0
How about specifying 2 digits and instructing users to put a 0 in front of any number less than 10...??
 
Upvote 0
Gene

Sorry, you've lost me.

How is VBA to know when you've typed in the correct no of digits?

What is the correct no of digits?

Why wouldn't checking the length work?

Perhaps I wasn't clear. Let's say I want to type 11 into the textbox. Here is what happens: The moment I type the first "1" into the textbox, as far as VBA is concerned, the change event has occured. Thus my code starts. Numbers start being reported. Other numbers start being bolded. All this is happening, EVENTHOUGH I am not finished entering my number. If you are saying "How is VBA supposed to know that I have typed in the correct number of digits", then I gather you are saying that there is no good way to type in a n digit number (if n happens to be >1) since VBA can't know what I intend. If that is the case, I can (I guess I have no choice) accept it, but I am amazed at it. Everyone up to now has just lived with this fact?

Gene
 
Upvote 0

Forum statistics

Threads
1,215,722
Messages
6,126,464
Members
449,315
Latest member
misterzim

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