Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) If Not IsNumeric(Chr(KeyCode)) Then MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus End Sub
修改了一下,楼主试试看。Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 Then MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus End If End Sub
刚才没留意,呵呵Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 Then MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus End If End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then MsgBox "请输入数字,谢谢" Text1.SelStart = Len(Form1.Text1.Text) Text1.SetFocus End If End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 Then MsgBox "请输入数字,谢谢": Text1.Text = "": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus End If End Sub 呵呵~谢谢各位~
刚刚在修改一下,这样就不能在一组数字出现超过一个小数点。Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 46 And 0 < InStr(Form1.Text1.Text, ".") Then KeyAscii = 0 If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 And KeyAscii <> 0 Then MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus End If End Sub
Private Sub Form_Load() Text1 = "" End SubPrivate Sub Text1_Change() If Not IsNumeric(Text1) And Text1 <> "" Then Text1 = Left(Text1, Len(Text1) - 1) Text1.SelStart = Len(Text1) MsgBox "请输入数字,谢谢" End If
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Not IsNumeric(Chr(KeyCode)) Then MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
End Sub
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 Then
MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
End If
End Sub
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 Then
MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
MsgBox "请输入数字,谢谢"
Text1.SelStart = Len(Form1.Text1.Text)
Text1.SetFocus
End If
End Sub
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 Then
MsgBox "请输入数字,谢谢": Text1.Text = "": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
End If
End Sub
呵呵~谢谢各位~
If KeyAscii = 46 And 0 < InStr(Form1.Text1.Text, ".") Then KeyAscii = 0
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 And KeyAscii <> 0 Then
MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
End If
End Sub
Private Sub Form_Load()
Text1 = ""
End SubPrivate Sub Text1_Change()
If Not IsNumeric(Text1) And Text1 <> "" Then
Text1 = Left(Text1, Len(Text1) - 1)
Text1.SelStart = Len(Text1)
MsgBox "请输入数字,谢谢"
End If
End Sub