Public Sub Text1_KeyPRESS(Index As Integer, Keyascii As Integer)
Dim j As Integer
j = 0
Do
Text1(j).IMEMode = 3 '全角转换成半角,也就是小数点不能变成句号
If Keyascii < 45 Or Keyascii > 57 Or Keyascii = 47 Xor Keyascii = 8 Xor Keyascii = 13 Then '限制输入没用字符
Keyascii = 0
End If
'禁止负号重复写If Text1(j).SelStart > 0 And Keyascii = 45 And Text1(j).SelLength < Len(Text1(j)) Then
Keyascii = 0
End If
If Left(Text1(j), 1) = "-" And Keyascii = 45 And Text1(j).SelLength < Len(Text1(j)) Then
Keyascii = 0
End If
If InStr(Text1(j), ".") > 0 And Keyascii = 46 And Text1(j).SelLength < Len(Text1(j)) Then Keyascii = 0 '禁止小数点重复写
If Keyascii = 13 And Index = j Then
If j = 3 Then
Text1(0).SetFocus
Exit Sub
End IfText1(j + 1).SetFocus
End If
j = j + 1
Loop Until j = Text1.Count
End Sub我写了以上代码,是想让文本框中只能输入数字,小数点每个文本框只能输入一次,负号每个文本框只能输入一次,且只能在第一个。现在的问题是所有文本框总共只能输入一个小数点一个负号。怎么解决呢?
Dim j As Integer
j = 0
Do
Text1(j).IMEMode = 3 '全角转换成半角,也就是小数点不能变成句号
If Keyascii < 45 Or Keyascii > 57 Or Keyascii = 47 Xor Keyascii = 8 Xor Keyascii = 13 Then '限制输入没用字符
Keyascii = 0
End If
'禁止负号重复写If Text1(j).SelStart > 0 And Keyascii = 45 And Text1(j).SelLength < Len(Text1(j)) Then
Keyascii = 0
End If
If Left(Text1(j), 1) = "-" And Keyascii = 45 And Text1(j).SelLength < Len(Text1(j)) Then
Keyascii = 0
End If
If InStr(Text1(j), ".") > 0 And Keyascii = 46 And Text1(j).SelLength < Len(Text1(j)) Then Keyascii = 0 '禁止小数点重复写
If Keyascii = 13 And Index = j Then
If j = 3 Then
Text1(0).SetFocus
Exit Sub
End IfText1(j + 1).SetFocus
End If
j = j + 1
Loop Until j = Text1.Count
End Sub我写了以上代码,是想让文本框中只能输入数字,小数点每个文本框只能输入一次,负号每个文本框只能输入一次,且只能在第一个。现在的问题是所有文本框总共只能输入一个小数点一个负号。怎么解决呢?
解决方案 »
- VB6.0 树形菜单如何禁用里面的复选框,让他不可用
- datagrid中怎样取得一个单元格的值
- ●300分真心真意,用insert 语句怎么才能吧图片插到数据库中。
- 在MSHFLEXGRID中如何判定特定的字段在哪一列?并将列值传给鼠标值?
- vb如何通过API关闭其他运行的程序窗口?
- 急聘!!
- 请问怎样在Listview在详细资料显示方式下能够将第一行的内容单击鼠标左键拖到第二行去呀?指点一下我,谢谢!
- 我错哪儿了?
- 图里面显示“呵呵”两个字的显示框,可以用鼠标拖动的,用VB怎么样实现的呀
- 有谁愿意为我分担情感故事!!!!!!!
- datagrid 下标越界(在线等!!)请大家多帮忙啊!
- VB访问sqlite数据库
private sub text1_lostfocus()
if trim(text1.text)<>"" then
if not isnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.text=""
text1.setfocus
end if
end if
end sub
dim Bak() as dobule '在窗体 load 事件中,重新定义数组与 Text1 的控件数组总数相等Private Sub Text1_Change(Index As Integer)
if not isnumeric(Text1(index).text) then
text1(index).text=bak(Index)
else
bak(Index)=text1(index)
end if
End Sub
Option Explicit
Dim Bak() As DoublePrivate Sub Form_Load()
ReDim Bak(Text1.Count) As Double
End SubPrivate Sub Text1_Change(Index As Integer)
Dim Pos As Long
Pos = Text1(Index).SelStart
If Not IsNumeric(Text1(Index)) Then
Text1(Index).Text = Bak(Index)
Else
Bak(Index) = Text1(Index).Text
End If
Text1(Index).SelStart = Pos
End Sub
意外发现,在进一步做程序时,加了后面的代码,前段程序没做任何改动,居然顺利实现我上面提出的要求了。高兴是高兴,可为什么呢?
Public Sub Text1_KeyPRESS(Index As Integer, Keyascii As Integer)
Dim j As Integer
j = 0
Do
Text1(j).IMEMode = 3 '全角转换成半角,也就是小数点不能变成句号
If Keyascii < 45 Or Keyascii > 57 Or Keyascii = 47 Xor Keyascii = 8 Xor Keyascii = 13 Then '限制输入没用字符
Keyascii = 0
End If
'禁止负号重复写If Text1(j).SelStart > 0 And Keyascii = 45 And Text1(j).SelLength < Len(Text1(j)) Then
Keyascii = 0
End If
If Left(Text1(j), 1) = "-" And Keyascii = 45 And Text1(j).SelLength < Len(Text1(j)) Then
Keyascii = 0
End If
If InStr(Text1(j), ".") > 0 And Keyascii = 46 And Text1(j).SelLength < Len(Text1(j)) Then Keyascii = 0 '禁止小数点重复写
If Keyascii = 13 And Index = j Then
If j = 3 Then
Text1(0).SetFocus
Exit Sub
End IfText1(j + 1).SetFocus
End If
j = j + 1
Loop Until j = Text1.CountEnd Sub
Private Sub Text1_gotfocus(Index As Integer)
Dim j As Integer
j = 0
Do
Text1(j).SelStart = 0
Text1(j).SelLength = Len(Text1(j))
j = j + 1
Loop Until j = Text1.Count
End Sub