Here is a way to enforce numeric input into a text box.
Any other character will not appear in the text box; it will
be removed by the code after it is typed.
Private Sub TextBox1_Change()
Dim txtBoxText As String
txtBoxText = TextBox1.Value
If InStr("0123456789", Right(TextBox1.Value, 1)) = 0 Then
TextBox1.Value = Mid(txtBoxText, 1, (Len(txtBoxText) - 1))
End If
End Sub
This is how you might convert the text box value for use in a numeric calculation.
Private Sub CommandButton1_Click()
If Len(TextBox1.Text) > 0 Then
MsgBox "That number doubled is " & CLng(TextBox1.Text) * 2
End If
End Sub
Bookmarks