比如你的TextBox控件名為 TxtEdit,則:
Private Sub TxtEdit_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
If KeyAscii = Asc(".") Then
If InStrRev(TxtEdit.Text, ".") > 0 Then
KeyAscii = 0
Else
Exit Sub
End If
End If
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then KeyAscii = 0
end sub