新建From1(窗体),新建Text1(TextBox),Command1(按钮CommandButton),代码:
Private Sub Text1_KeyPress(KeyAscii As Integer) '只能输入数字 If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 End If End Sub