将下面代码贴入窗体中即可(画个Textbox )
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not (Chr(KeyAscii) > "0" And Chr(KeyAscii) < "9" Or Chr(KeyAscii) = "." Or KeyAscii = vbKeyBack) Then
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii >= 32 And KeyAscii <= 45) Or KeyAscii = 47 Or _
(KeyAscii >= 58 And KeyAscii <= 126) Then
KeyAscii = 0
Else
If InStr(1, Text1.Text, ".", vbTextCompare) > 0 And KeyAscii = 46 Then
KeyAscii = 0
End If
End If
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim Ancien As String
Ancien = Me.Text2
If KeyAscii = 46 And Text2.Tag <> "R" Then KeyAscii = 0: Exit Sub
If IsNumeric(Me.Text2 & Chr(KeyAscii)) Then
Else
KeyAscii = 0
End If