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