我想实现的功能是,输入框的内容只能输入预先规定的字符,并且动态观察,如果数值大于大于10,则弹出提示。可是选择是的时候,为什么对话框的内容还是不对??还是大于10Option Explicit
Dim IntegerNum As String    
IntegerNum = "0123456789"Function TestText(KeyIn As Integer, ListString As String, EditBasp As Boolean) As Integer
    Dim KeyOut As Integer                          '返回值变量
    Dim TestDATList As String
    TestDATList = UCase(ListString) & Chr(8)       '添加 BackSpace 按键
    If InStr(1, TestDATList, Chr(KeyIn)) > 0 Then  '键值是否在表中
        KeyOut = KeyIn                             '是则允许输入
    Else
        KeyOut = 0                     '否则,不允许
    End If
    TestText = KeyOut                  '返回结果
End FunctionPrivate Sub TxtPrintRange_KeyPress(KeyAscii As Integer)
    Dim IntR As Integer
    KeyAscii = TestText(KeyAscii, (IntegerNum), True)  
    If Val(TxtPrintRange.Text) > 10 Then
        IntR = MsgBox("间隔代数太大,自动调整为 10 ? ", 4, "间隔代数")
        If IntR = 6 Then       ' 选择 是
            TxtPrintRange.Text = 10
            NprintRange = 10
        ElseIf IntR = 7 Then    '选择 否
            TxtPrintRange.Text = ""
        End If
    End If
End Sub

解决方案 »

  1.   

    Dim IntegerNum As String
    Function TestText(KeyIn As Integer, ListString As String, EditBasp As Boolean) As Integer
        Dim KeyOut As Integer                          '返回值变量
        Dim TestDATList As String
        TestDATList = UCase(ListString) & Chr(8)       '添加 BackSpace 按键
        If InStr(1, TestDATList, Chr(KeyIn)) > 0 Then  '键值是否在表中
            KeyOut = KeyIn                             '是则允许输入
        Else
            KeyOut = 0                     '否则,不允许
        End If
        TestText = KeyOut                  '返回结果
    End FunctionPrivate Sub Form_Load()
    IntegerNum = "0123456789"
    End SubPrivate Sub TxtPrintRange_Change()
    Dim IntR As Integer
    If Val(TxtPrintRange.Text) > 10 Then
            IntR = MsgBox("间隔代数太大,自动调整为 10 ? ", 4, "间隔代数")
            If IntR = 6 Then       ' 选择 是
                TxtPrintRange.Text = 10
                'NprintRange = 10
            ElseIf IntR = 7 Then    '选择 否
                TxtPrintRange.Text = ""
            End If
        End If
    End SubPrivate Sub TxtPrintRange_KeyPress(KeyAscii As Integer)
        Dim IntR As Integer
        KeyAscii = TestText(KeyAscii, (IntegerNum), True)
        
    End Sub
      

  2.   


    Private Sub TxtPrintRange_KeyUp(KeyCode As Integer, Shift As Integer)
        Dim IntR As Integer
        KeyCode = TestText(KeyCode, (IntegerNum), True)
        If Val(TxtPrintRange.Text) > 10 Then
            IntR = MsgBox("间隔代数太大,自动调整为 10 ? ", 4, "间隔代数")
            If IntR = 6 Then       ' 选择 是
                KeyCode = 0
                TxtPrintRange.Text = 10
    '            NprintRange = 10
            ElseIf IntR = 7 Then    '选择 否
                KeyCode = 0
                TxtPrintRange.Text = ""
            End If
        End If
    End Sub
      

  3.   

    我帮你改了你试试:Option Explicit
    Dim IntegerNum As String
    Function TestText(KeyIn As Integer, ListString As String, EditBasp As Boolean) As Integer
        Dim KeyOut As Integer                          '返回值变量
        Dim TestDATList As String
        TestDATList = UCase(ListString) & Chr(8)       '添加 BackSpace 按键
        If InStr(1, TestDATList, Chr(KeyIn)) > 0 Then  '键值是否在表中
            KeyOut = KeyIn                             '是则允许输入
        Else
            KeyOut = 0                     '否则,不允许
        End If
        TestText = KeyOut                  '返回结果
    End FunctionPrivate Sub Form_Load()
    IntegerNum = "0123456789"
    End Sub