请教 如何让text不能输入 中文,或其他的字符串 只能输入Integer类型的
Private Sub TxtSclPaid2_KeyPress(KeyAscii As MSForms.ReturnInteger)
KeyChk KeyAscii, 1
End Sub
使用以上的语句 对中文没有生效

解决方案 »

  1.   

    给你个例子吧
    Private Sub TxtCloseStep_KeyPress(Index As Integer, KeyAscii As Integer)
        If KeyAscii > 57 Or KeyAscii < 48 Then
            If KeyAscii <> 8 Then
                KeyAscii = 0
            End If
        End If
    End Sub
      

  2.   

    Private Sub txtFee_KeyPress(KeyAscii As Integer)
        Dim strNumbers As String
        strNumbers = "1234567890" + Chr(8) + Chr(46)
        
        If InStr(strNumbers, Chr(KeyAscii)) = 0 Then
            KeyAscii = 0
        End If
    End Sub
      

  3.   

    private sub Text1_change()
         text1=trim(text1) 
         if not isnumberic(text1) then
             msgbox "对不起你只能输入数值。"
             Text1.SelStart = 0
             Text1.SelStart = Len(Text1)
         endif
    end sub
      

  4.   

    Private Sub txt1_KeyPress(KeyAscii As Integer)
        if keyascii> 0x39 adn keyascii<0x30 then
            msgbox "对不起你只能输入数值。"
            txt1.text=mid(txt1.text,1,len(txt1.text))
        endif
    End Sub因为数字的ASCII码为0x30-0x39
    故可以根据此将范围外的输入取消
      

  5.   

    Private Sub txt1_KeyPress(KeyAscii As Integer)
        Select Case KeyAscii
        Case VbKey0 to VbKey9,VbKeyback,VbKeyDelete   '允许输入0-9和退格键和删除键
        Case Else
             KeyAscii=0
        end Select
    End Sub
      

  6.   

    Private Sub TxtCloseStep_KeyPress(Index As Integer, KeyAscii As Integer)
        If KeyAscii >asc(9) Or KeyAscii < asc(0) or keascii<>8 Then
                KeyAscii = 0
        End If
    End Sub