Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = Asc(".") Then If Len(Text1.Text) - Len(Replace(Text1.Text, ".", "")) > 0 Then KeyAscii = 0 End If End Sub
If textbox1.Text.IndexOf(".") > 0 Then Exit Sub Else textbox1.Text = textbox1.text & "." End If
如果用keypress事件处理的话,你粘贴一下非法字符试一下看看。Dim s As StringPrivate Sub Text1_Change() Dim n As Long If Not IsNumeric(Text1.Text) Then n = Text1.SelStart Text1.Text = s Text1.SelStart = n Else s = Text1.Text End If End Sub═══════════════════ http://www.egooglet.com 资料、源码下载http://bbs.j2soft.cn 论坛交流 ═══════════════════
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) '利用其中的Index來判斷是哪一個Text End Sub
jadeluo(秀峰) 的方法 + DengXingJie(杰西) 的方法。 :) 晚了一步
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) '利用其中的Index來判斷是哪一個Text End Sub 具体的语法是怎么样的呀
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) If KeyAscii = Asc(".") And Index = 0 Then If Instr(Text1(0), ".") Then KeyAscii = 0 End If End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) If KeyAscii = Asc(".") And Index = 0 Then If InStr(Text1(0), ".") Then KeyAscii = 0 End If If KeyAscii = Asc(".") And Index = 0 Then If InStr(Text1(1), ".") Then KeyAscii = 0 End If End Sub 不可以呀 text1(1).text 还是可以输入
要控制text1(0).text index=0 要控制text1(1).text index=1 要控制text1(2).text index=2 要控制text1(3).text index=3 .... 在这里改:If KeyAscii = Asc(".") And Index = 0 Then
If KeyAscii = Asc(".") Then
If Len(Text1.Text) - Len(Replace(Text1.Text, ".", "")) > 0 Then KeyAscii = 0
End If
End Sub
Exit Sub
Else
textbox1.Text = textbox1.text & "."
End If
Dim n As Long If Not IsNumeric(Text1.Text) Then
n = Text1.SelStart
Text1.Text = s
Text1.SelStart = n
Else
s = Text1.Text
End If
End Sub═══════════════════
http://www.egooglet.com 资料、源码下载http://bbs.j2soft.cn 论坛交流
═══════════════════
我是text1(0).text
text1(1).text
text1(2).text
text1(3).text
把text1.text 控制了,其他的都不能输入“.”了
有没有解决办法呀
'利用其中的Index來判斷是哪一個Text
End Sub
:)
晚了一步
'利用其中的Index來判斷是哪一個Text
End Sub
具体的语法是怎么样的呀
If KeyAscii = Asc(".") And Index = 0 Then
If Instr(Text1(0), ".") Then KeyAscii = 0
End If
End Sub
If KeyAscii = Asc(".") And Index = 0 Then
If InStr(Text1(0), ".") Then KeyAscii = 0
End If
If KeyAscii = Asc(".") And Index = 0 Then
If InStr(Text1(1), ".") Then KeyAscii = 0
End If
End Sub
不可以呀
text1(1).text 还是可以输入
要控制text1(1).text index=1
要控制text1(2).text index=2
要控制text1(3).text index=3
....
在这里改:If KeyAscii = Asc(".") And Index = 0 Then