vb 有30个text,要求只能输入数字,要用1个代码,怎么才能让30个text调用?
PrivateSubText1_KeyPress(KeyAsciiAsInteger)'textbox只能输入数字,以及退格SelectCaseKeyAsciiCase8...
Private Sub Text1_KeyPress(KeyAscii As Integer) 'textbox只能输入数字,以及退格
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
然后怎么改? 展开
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
然后怎么改? 展开
2个回答
展开全部
第一步:把Text2的名称改成Text1,这时会提示“已经存在Text1,是否创建数组”,请单击“是”
第二步,把所有其他的28个文本框都改成Text1
第三步,把
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
改成
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
现在,你会发现,这30个文本框都是只能输入数字了。
请及时采纳对你有帮助的答案!
第二步,把所有其他的28个文本框都改成Text1
第三步,把
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
改成
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
现在,你会发现,这30个文本框都是只能输入数字了。
请及时采纳对你有帮助的答案!
展开全部
public sub numonly (keyascii as integer)
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
call numonly(keyascii)
end sub
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
call numonly(keyascii)
end sub
参考资料: 用控件数组不是更好吗
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询