
VB中怎样限制Text控件数组中的不同Text输入不同内容(比如文字、数字等)
各位高手求救:我这里定义了Text1(i)控件数组,其中i=0to5,现在的问题就是怎样限制第一个只能输入文字,第三、四、五个只能输入数字。我定义了一个函数限制的是整个控...
各位高手求救:我这里定义了Text1(i)控件数组,其中 i = 0 to 5,现在的问题就是怎样限制第一个只能输入文字,第三、四、五个只能输入数字。我定义了一个函数限制的是整个控件数组都不能输入文字或者数字,请问怎样才能在控件数组中实现对不同的文本框输入不同内容的限制?
展开
展开全部
校验控件数组的index ..也就是你说的i
if i=0 then 只能输入数字
if i=3 or i=4 or i=5 the 只能输入文字
我自己写了一个,按你说的文本框数组,0-5,其中0只能输入数字,3-5只能输入文字(字母a-z,A-Z),然后1和2可以随便输入..
全部代码:
Private Sub Form_Load()
For i = 0 To 5
Text1(i) = ""
Next
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
KeyAscii = xy(Index, KeyAscii)
End Sub
Function xy(Index As Integer, KeyAscii As Integer) As Integer
xy = 0
If KeyAscii = 8 Or KeyAscii = 46 Then
xy = KeyAscii '如果输入是del或退格,允许
Else
If Index = 0 And KeyAscii > 47 And KeyAscii < 58 Then
xy = KeyAscii 'i=0的文本框只能输入数字0-9
ElseIf (Index = 3 Or Index = 4 Or Index = 5) And ((KeyAscii > 64 And KeyAscii < 91) Or (KeyAscii > 96 And KeyAscii < 123)) Then
xy = KeyAscii 'i=3.4.5的文本框只能输入字母a-z,A-Z
ElseIf Index = 1 Or Index = 2 Then
xy = KeyAscii 'i=1,2的文本框随便输入
End If
End If
End Function
if i=0 then 只能输入数字
if i=3 or i=4 or i=5 the 只能输入文字
我自己写了一个,按你说的文本框数组,0-5,其中0只能输入数字,3-5只能输入文字(字母a-z,A-Z),然后1和2可以随便输入..
全部代码:
Private Sub Form_Load()
For i = 0 To 5
Text1(i) = ""
Next
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
KeyAscii = xy(Index, KeyAscii)
End Sub
Function xy(Index As Integer, KeyAscii As Integer) As Integer
xy = 0
If KeyAscii = 8 Or KeyAscii = 46 Then
xy = KeyAscii '如果输入是del或退格,允许
Else
If Index = 0 And KeyAscii > 47 And KeyAscii < 58 Then
xy = KeyAscii 'i=0的文本框只能输入数字0-9
ElseIf (Index = 3 Or Index = 4 Or Index = 5) And ((KeyAscii > 64 And KeyAscii < 91) Or (KeyAscii > 96 And KeyAscii < 123)) Then
xy = KeyAscii 'i=3.4.5的文本框只能输入字母a-z,A-Z
ElseIf Index = 1 Or Index = 2 Then
xy = KeyAscii 'i=1,2的文本框随便输入
End If
End If
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询