上午还好好的,下午不知道为什么,textbox里面只能数入一个值了,譬如我输入1234,上午就是1234,下午的时候,输入了1,然后再输入2的时候,1就被2取代了,我看了看textbox的属性啊什么的,我都没有动啊,最大能输入7位数的。肯定是自己写程序的时候不小心改了什么,但是我有不知道改了哪里。大家有什么好办法么?

解决方案 »

  1.   

    检查一下keypress事件里是否写入了什么相关的代码。
      

  2.   

    我就照这个大哥教的作了
    Private Sub Form_Load()
       Check1.Caption = "英文"
       Check2.Caption = "数字"
       Check1.Value = 1
       Check2.Value = 1
       Text1.Text = ""
       flg = True
    End SubPrivate Sub Text1_Change()
       If Not flg And Len(Text1.Text) >= 1 Then
         Text1.Text = Replace(Text1.Text, Chr(k_code), "")
         flg = True
         k_code = ""
         Text1.SelStart = Len(Text1.Text)
       End If
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
       Select Case KeyAscii
       Case 48 To 57
          If Check2.Value <> 1 Then MsgBox "不能输入数字": flg = False: k_code = KeyAscii
       Case 65 To 90, 97 To 122
          If Check1.Value <> 1 Then MsgBox "不能输入英文": flg = False: k_code = KeyAscii
       Case Else
          MsgBox "非法字符!": flg = False: k_code = KeyAscii
       End Select
     If KeyAscii >= 97 And KeyAscii <= 122 Then
       KeyAscii = KeyAscii - 32
     End If
    End Sub
    这里面有什么错么?我气是只想要得到这样的结果 ,就是两个textbox里面都能输入ZA123或者12345,但是*/-什么的输入就出现msgbox 提示输入错误。结果现在只能输入1个数,郁闷的要死
      

  3.   

    你的做法怪异!
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case 48 To 57
    If Check2.Value <> 1 Then MsgBox "不能输入数字": flg = False:  KeyAscii=0
    Case 65 To 90, 97 To 122
    If Check1.Value <> 1 Then MsgBox "不能输入英文": flg = False:  KeyAscii=0
    Case Else
    MsgBox "非法字符!": flg = False: KeyAscii=0
    End Select
    If KeyAscii >= 97 And KeyAscii <= 122 Then
    KeyAscii = KeyAscii - 32
    End If
    End Sub
    这样不就行了!
      

  4.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
      Select Case KeyAscii
       Case 48 To 57
          If Check2.Value <> 1 Then MsgBox "不能輸入數字": KeyAscii = 0
           
       Case 65 To 90, 97 To 122
          If Check1.Value <> 1 Then MsgBox "不能輸入英文": KeyAscii = 0
            
       Case KeyAscii <> 8 Or KeyAscii <> 13 '不能把刪除鍵和回車鍵屏閉了
                                            '8 BackSpace,13 Enter
          MsgBox "非法字符!": KeyAscii = 0
       End Select
       
     If KeyAscii >= 97 And KeyAscii <= 122 Then
       KeyAscii = KeyAscii - 32
     End IfEnd Sub
    Text_Change用不上
      

  5.   

    Private Sub Form_Load()
       Text1.Text = ""
       Text2.Text = ""
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
       Select Case KeyAscii
       Case 48 To 57,65 To 90, 97 To 122
          If KeyAscii >= 97 Then KeyAscii = KeyAscii - 32
       Case Else
          MsgBox "非法字符!": KeyAscii =asc(vbnullstring)
       End Select
    End Sub