展开全部
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyHome, vbKeyLeft, vbKeyUp '限制只能在末尾输入
KeyCode = 0
End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 46 '小数点
If Text1 = "" Then
Text1 = "0" 'Text1无内容时输入小数点,自动在小数点之前添加0
Text1.SelStart = 1
Else
If InStr(Text1, ".") > 0 Then KeyAscii = 0 '禁止重复输入小数点
End If
Case 48 '0
If Text1 = "" Then
Text1 = "0."
Text1.SelStart = 2
KeyAscii = 0
End If
Case 49 To 57 '1-9
If Left(Text1, 1) = "0" And InStr(Text1, ".") = 0 Then
Text1 = Mid(Text1, 2)
Text1.SelStart = Len(Text1)
End If
Case vbKeyBack '支持退格键
If Right(Text1, 1) = "." Then
If Val(Text1) = 0 Then
Text1 = ""
KeyAscii = 0
End If
End If
Case Else
MsgBox "请输入数字或小数点!"
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyHome, vbKeyLeft, vbKeyUp '限制只能在末尾输入
KeyCode = 0
End Select
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.SelStart = Len(Text1) '限制只能在末尾输入
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.SelStart = Len(Text1) '限制只能在末尾输入(取消选择)
End Sub
Select Case KeyCode
Case vbKeyHome, vbKeyLeft, vbKeyUp '限制只能在末尾输入
KeyCode = 0
End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 46 '小数点
If Text1 = "" Then
Text1 = "0" 'Text1无内容时输入小数点,自动在小数点之前添加0
Text1.SelStart = 1
Else
If InStr(Text1, ".") > 0 Then KeyAscii = 0 '禁止重复输入小数点
End If
Case 48 '0
If Text1 = "" Then
Text1 = "0."
Text1.SelStart = 2
KeyAscii = 0
End If
Case 49 To 57 '1-9
If Left(Text1, 1) = "0" And InStr(Text1, ".") = 0 Then
Text1 = Mid(Text1, 2)
Text1.SelStart = Len(Text1)
End If
Case vbKeyBack '支持退格键
If Right(Text1, 1) = "." Then
If Val(Text1) = 0 Then
Text1 = ""
KeyAscii = 0
End If
End If
Case Else
MsgBox "请输入数字或小数点!"
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyHome, vbKeyLeft, vbKeyUp '限制只能在末尾输入
KeyCode = 0
End Select
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.SelStart = Len(Text1) '限制只能在末尾输入
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.SelStart = Len(Text1) '限制只能在末尾输入(取消选择)
End Sub
展开全部
Private Sub Text1_Change() '文本框更改事件
If Not IsNumeric(Text1.Text) Then '判断文本框内是否为数字
MsgBox "请输入数字", vbCritical '若非数字,所错
Text1.SelStart = Len(Text1.Text) - 1 '并自动选中刚刚输入的字符
Text1.SelLength = 1 '以便重新输入正确的字符
End If
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ISNUMBER函数只有一个参数value,表示进行检验的内容,如果检验的内容为数字,将返回TRUE,否则将返回FALSE。
IS类的函数的value参数是不可以转换的。如在其他大多数需要数字的函数中,文本值“13”并不会有文本值转换成数字13,而是公式“=ISNUMBER(”13“)”中,“13”并不会由文本值转换成其他类型的值,因此函数ISNUMBER会返回FALSE值,认为该函数不是数字。
a=mid(text1.text,2,len(text1.text)-2)
if isnumber(a)=false then
msgbox"错误"
end if
IS类的函数的value参数是不可以转换的。如在其他大多数需要数字的函数中,文本值“13”并不会有文本值转换成数字13,而是公式“=ISNUMBER(”13“)”中,“13”并不会由文本值转换成其他类型的值,因此函数ISNUMBER会返回FALSE值,认为该函数不是数字。
a=mid(text1.text,2,len(text1.text)-2)
if isnumber(a)=false then
msgbox"错误"
end if
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询