首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

重复的text内容请达人帮忙精简 送分哦解决思路

2012-03-08 
重复的text内容请达人帮忙精简 送分哦PrivateSubText1_KeyPress(KeyAsciiAsInteger)DimNumbersAsStringNum

重复的text内容请达人帮忙精简 送分哦
Private   Sub   Text1_KeyPress(KeyAscii   As   Integer)
Dim   Numbers   As   String
Numbers   =   "1234567890 "   +   Chr(8)   +   Chr(46)
If   InStr(Numbers,   Chr(KeyAscii))   =   0   Then
KeyAscii   =   0
End   If
End   Sub
Private   Sub   Text2_KeyPress(KeyAscii   As   Integer)
Dim   Numbers   As   String
Numbers   =   "1234567890 "   +   Chr(8)   +   Chr(46)
If   InStr(Numbers,   Chr(KeyAscii))   =   0   Then
KeyAscii   =   0
End   If
End   Sub
Private   Sub   Text4_KeyPress(KeyAscii   As   Integer)
Dim   Numbers   As   String
Numbers   =   "1234567890 "   +   Chr(8)   +   Chr(46)
If   InStr(Numbers,   Chr(KeyAscii))   =   0   Then
KeyAscii   =   0
End   If
End   Sub
Private   Sub   Text5_KeyPress(KeyAscii   As   Integer)
Dim   Numbers   As   String
Numbers   =   "1234567890 "   +   Chr(8)   +   Chr(46)
If   InStr(Numbers,   Chr(KeyAscii))   =   0   Then
KeyAscii   =   0
End   If
End   Sub

重复的text内容我把text2~text5   删除   然后复制4份text1用数组控件精简成

Private   Sub   Text1_KeyPress(KeyAscii   As   Integer)
Dim   Numbers   As   String
Numbers   =   "1234567890 "   +   Chr(8)   +   Chr(46)
If   InStr(Numbers,   Chr(KeyAscii))   =   0   Then
KeyAscii   =   0
End   If
End   Sub

之后
Private   Sub   Text1_KeyPress(KeyAscii   As   Integer)或
Private   Sub   Text1(i)_KeyPress(KeyAscii   As   Integer)
都不能执行啊   请帮忙解决


[解决办法]
1,控件数组
步骤
放textbox在form里面,然后copy paste声成控件数组
然后再keypress中写
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
Dim Numbers As String
Numbers = "1234567890 " + Chr(8) + Chr(46)
If InStr(Numbers, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub

热点排行