vb textbox 文本框 输入数字及要求 符合的给高分
用vb2做两个textbox,其中1个只能输入0-9数字,另一个只能输入15-22之间的数字,又符合的给高加分!!IfText2<15OrText2>22这句有问题错误2...
用vb2做两个textbox,其中1个只能输入0-9数字,另一个只能输入15-22之间的数字,又符合的给高加分!!
If Text2 < 15 Or Text2 > 22 这句有问题 错误 2 没有为类型“System.Windows.Forms.TextBox”和“Integer”定义运算符“>”。 D:\Backup\我的文档\Visual Studio 2008\Projects\WindowsApplication6\WindowsApplication6\Form1.vb 21 26 WindowsApplication6
还有Text2 = "",错误 3 类型“String”的值无法转换为“System.Windows.Forms.TextBox”。 D:\Backup\我的文档\Visual Studio 2008\Projects\WindowsApplication6\WindowsApplication6\Form1.vb 22 21 WindowsApplication6 展开
If Text2 < 15 Or Text2 > 22 这句有问题 错误 2 没有为类型“System.Windows.Forms.TextBox”和“Integer”定义运算符“>”。 D:\Backup\我的文档\Visual Studio 2008\Projects\WindowsApplication6\WindowsApplication6\Form1.vb 21 26 WindowsApplication6
还有Text2 = "",错误 3 类型“String”的值无法转换为“System.Windows.Forms.TextBox”。 D:\Backup\我的文档\Visual Studio 2008\Projects\WindowsApplication6\WindowsApplication6\Form1.vb 22 21 WindowsApplication6 展开
展开全部
加入以下代码就可以实现了:
Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub
Private Sub Text1_Change()
If Len(Text1) = 2 Then Text1 = Left(Text1, Len(Text1.Text) - 1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
Private Sub Text2_Change()
If Len(Text2) = 3 Then Text2 = Left(Text2, Len(Text2.Text) - 1)
If Len(Text2) = 2 And (Val(Text2) < 15 Or Val(Text2) > 22) Then Text2 = ""
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
Private Sub Text2_LostFocus()
If Len(Text2) = 1 Then Text2.SetFocus
End Sub
已经运行过。
功能:在text1中只能输入0-9之间的数字。在text2中只能输入15-22之间的数字,当然也可以不输入(保留空的状态),否则光标不能停止输入。
还有什么问题没有?
Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub
Private Sub Text1_Change()
If Len(Text1) = 2 Then Text1 = Left(Text1, Len(Text1.Text) - 1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
Private Sub Text2_Change()
If Len(Text2) = 3 Then Text2 = Left(Text2, Len(Text2.Text) - 1)
If Len(Text2) = 2 And (Val(Text2) < 15 Or Val(Text2) > 22) Then Text2 = ""
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
Private Sub Text2_LostFocus()
If Len(Text2) = 1 Then Text2.SetFocus
End Sub
已经运行过。
功能:在text1中只能输入0-9之间的数字。在text2中只能输入15-22之间的数字,当然也可以不输入(保留空的状态),否则光标不能停止输入。
还有什么问题没有?
展开全部
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 8
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 8
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text2_LostFocus()
If Text2.text < 15 Or Text2.text > 22 Then
Text2.text = ""
MsgBox "只能输入15-22之间的数字"
End If
End Sub
.NET里???在TEXT2后面加.TEXT试试
Select Case KeyAscii
Case 48 To 57, 8
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 8
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text2_LostFocus()
If Text2.text < 15 Or Text2.text > 22 Then
Text2.text = ""
MsgBox "只能输入15-22之间的数字"
End If
End Sub
.NET里???在TEXT2后面加.TEXT试试
展开全部
代码不少:
Dim text1_flag As Boolean
Dim text2_flag As Boolean
Private Sub Text1_GotFocus()
text1_flag = True
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
If text1_flag = True And KeyAscii > 47 And KeyAscii < 58 Then
Text1.Text = ""
Else
KeyAscii = 0
End If
End Sub
Private Sub Text1_LostFocus()
text1_flag = False
End Sub
Private Sub Text2_GotFocus()
text2_flag = True
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
If text2_flag = True And KeyAscii > 47 And KeyAscii < 58 Then
If Text2 <> "" Then
If Val(Text2.Text & Chr(KeyAscii)) < 15 Or Val(Text2.Text & Chr(KeyAscii)) > 22 Then
KeyAscii = 0
End If
End If
Else
KeyAscii = 0
End If
End Sub
Private Sub Text2_LostFocus()
text2_flag = False
End Sub
Dim text1_flag As Boolean
Dim text2_flag As Boolean
Private Sub Text1_GotFocus()
text1_flag = True
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
If text1_flag = True And KeyAscii > 47 And KeyAscii < 58 Then
Text1.Text = ""
Else
KeyAscii = 0
End If
End Sub
Private Sub Text1_LostFocus()
text1_flag = False
End Sub
Private Sub Text2_GotFocus()
text2_flag = True
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
If text2_flag = True And KeyAscii > 47 And KeyAscii < 58 Then
If Text2 <> "" Then
If Val(Text2.Text & Chr(KeyAscii)) < 15 Or Val(Text2.Text & Chr(KeyAscii)) > 22 Then
KeyAscii = 0
End If
End If
Else
KeyAscii = 0
End If
End Sub
Private Sub Text2_LostFocus()
text2_flag = False
End Sub
展开全部
我的办法比楼上两位可要简单些:
Private Sub Text1_Change()
If Val(Text1.Text) < 0 Or Val(Text1.Text) > 9 Then
MsgBox "输入越界,程序输入"
Text1.Text = ""
End If
End Sub
Private Sub Text2_Change()
If (Val(Text2.Text) < 15 And Val(Text2.Text) > 9) Or Val(Text2.Text) > 22 Then
MsgBox "输入越界,程序输入"
Text2.Text = ""
End If
End Sub
Private Sub Text2_LostFocus()
If Text2.Text < 15 Then
MsgBox "输入越界,重新输入"
Text2.SetFocus
End If
End Sub
Private Sub Text1_Change()
If Val(Text1.Text) < 0 Or Val(Text1.Text) > 9 Then
MsgBox "输入越界,程序输入"
Text1.Text = ""
End If
End Sub
Private Sub Text2_Change()
If (Val(Text2.Text) < 15 And Val(Text2.Text) > 9) Or Val(Text2.Text) > 22 Then
MsgBox "输入越界,程序输入"
Text2.Text = ""
End If
End Sub
Private Sub Text2_LostFocus()
If Text2.Text < 15 Then
MsgBox "输入越界,重新输入"
Text2.SetFocus
End If
End Sub
展开全部
我也刚学vb两个星期不到,这道题我花了将近一个小时呢!好累,我吃饭去了…
Private Sub txt1_Change()
txt1.MaxLength = 1
txt2.SetFocus
End Sub
Private Sub txt1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 8
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub txt2_KeyPress(KeyAscii As Integer)
txt2.MaxLength = 2
If txt2 = "" Then
Select Case KeyAscii
Case 49, 50, 8
Case Else
KeyAscii = 0
End Select
End If
If txt2 = "1" Then
Select Case KeyAscii
Case 53 To 57, 8
Case Else
KeyAscii = 0
End Select
Else
Select Case KeyAscii
Case 48 To 50, 8
Case Else
KeyAscii = 0
End Select
End If
End Sub
Private Sub txt1_Change()
txt1.MaxLength = 1
txt2.SetFocus
End Sub
Private Sub txt1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 8
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub txt2_KeyPress(KeyAscii As Integer)
txt2.MaxLength = 2
If txt2 = "" Then
Select Case KeyAscii
Case 49, 50, 8
Case Else
KeyAscii = 0
End Select
End If
If txt2 = "1" Then
Select Case KeyAscii
Case 53 To 57, 8
Case Else
KeyAscii = 0
End Select
Else
Select Case KeyAscii
Case 48 To 50, 8
Case Else
KeyAscii = 0
End Select
End If
End Sub
展开全部
Private Sub Text1_Change()
If Val(Text1.Text) >= 10 Or Val(Text1.Text) < 0 Then
MsgBox "只能输入0-9数字"
text1.text=""
text1.SetFocus
End If
End Sub
Private Sub Text2_Change()
If Val(Text2.Text) >= 10 Or Val(Text2.Text) < 0 Then
MsgBox "只能输入15-22数字"
text2.text=""
text1.SetFocus
End If
End Sub
你试一下
If Val(Text1.Text) >= 10 Or Val(Text1.Text) < 0 Then
MsgBox "只能输入0-9数字"
text1.text=""
text1.SetFocus
End If
End Sub
Private Sub Text2_Change()
If Val(Text2.Text) >= 10 Or Val(Text2.Text) < 0 Then
MsgBox "只能输入15-22数字"
text2.text=""
text1.SetFocus
End If
End Sub
你试一下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |