vb中一个文本框中只能输一个数字并输完后跳到下一个文本框代码如何写
3个回答
展开全部
每个文本框的maxlength都设置成1 代码入下
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNumeric(Text1.Text) Then ' 用IsNumeric函数判断输入是否为数字
Text2.SetFocus '如果是数字 跳到下一个文本框
Else
Text1.Text = "" '如果不是数字 清空文本框重新输入
End If
End Sub
Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNumeric(Text2.Text) Then
Text3.SetFocus
Else
Text2.Text = ""
End If
End Sub
Private Sub Text3_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNumeric(Text3.Text) Then
Text4.SetFocus
Else
Text3.Text = ""
End If
End Sub
Private Sub Text4_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNumeric(Text4.Text) Then
Text5.SetFocus
Else
Text4.Text = ""
End If
End Sub
Private Sub Text5_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNumeric(Text5.Text) Then
Text6.SetFocus
Else
Text5.Text = ""
End If
End Sub
Private Sub Text6_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNumeric(Text6.Text) Then
'这里写输入完后要执行的代码 这里我只做了个输出
MsgBox "您输入的是" & Text1.Text & Text2.Text & Text3.Text & Text4.Text & Text5.Text & Text6.Text
Text1 = none '文本框全部清空
Text2 = none
Text3 = none
Text4 = none
Text5 = none
Text6 = none
Text1.SetFocus '第一个文本框重新获得焦点
Else
Text6.Text = ""
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询