2015-05-29 41 views
0

我有名为“txtPrice”的文本框有问题。我想从字符串保护这个文本框。如果我们输入一个字符串,它会显示我写的信息。但是如果我输入,例如“12r”,它什么也不做。如何保护文本框中的字符串?

Dim i As Integer 
Dim s As Long 
i = Asc(txtPrice) 
If i < 48 or i> 57 then 'ascii number 
    MsgBox "Error" 
End If 
+1

请解释'txtPrice'可接受的值。它是否只包含数字?是否允许? – HansUp

回答

0

你到底在找什么?在属性下,您可以指定输入掩码。

如果你正在寻找一个号码,你可以试试If Not IsNumeric(txtPrice)

如果你不希望任何字母,试试这个:

Dim intPos As Integer 

For intPos = 1 To Len(txtPrice) 
    Select Case Asc(Mid(txtPrice, intPos, 1)) 
     Case 65 To 90, 97 To 122 
      IsLetter = True 
     Case Else 
      IsLetter = False 
    End Select 
    If IsLetter Then Exit For 
Next intPos 

If IsLetter Then 
    MsgBox "Error" 
End If 
+0

是的,我只需要numberic.thank帮忙。 –

+0

没问题@ChenRina。 – Y2Que

相关问题