代码如下..我只想输入> < >= <= !这五个性符号.应该怎样判断呢?主函数调用下面的函数来判断..哪里有不对.请高手指教.
Public Function StrCheck1(ChkStr As Variant, ByRef ErrWord As String)
    Dim wstr() As String
    Dim i      As Integer
    StrCheck1 = True
    ErrWord = ""
        ReDim wstr(5)
        wstr(0) = ">"
        wstr(1) = "<"
        wstr(2) = ">="
        wstr(3) = "<="
        wstr(4) = "!="
    For i = LBound(wstr, 1) To UBound(wstr, 1)
        If InStr(1, CStr(ChkStr), wstr(i)) = 0 Then
            ErrWord = wstr(i)            StrCheck1 = False
        End If
    Next iEnd Function

解决方案 »

  1.   

    Public Function StrCheck1(ChkStr As Variant, ByRef ErrWord As String)
        Dim wstr() As String
        Dim i      As Integer
        
        StrCheck1 = True
        ErrWord = ""
            ReDim wstr(5)
            wstr(0) = ">"
            wstr(1) = " <"
            wstr(2) = ">="
            wstr(3) = " <="
            wstr(4) = "!="
            
        For i = LBound(wstr, 1) To UBound(wstr, 1)
            If InStr(1, CStr(ChkStr), wstr(i)) = 0 Then
                ErrWord = wstr(i)
                StrCheck1 = False
                Exit For
            End If
        Next iEnd Function
      

  2.   


    '你代码要实现的功能是:
    '-------判断chkstr中是否同时存在规定的5种字符,
    '如存在则函数返回True,引用变量ErrWord返回“”,
    '如果有不存在的,函数返回false,引用变量ErrWord返回首次未出现的字符
    Public Function StrCheck1(ChkStr As Variant, ByRef ErrWord As String)
        Dim wstr() As String    '定义动态数组
        
        Dim i      As Integer   '
        
        StrCheck1 = True   '先设定函数的默认返回值
        
        ErrWord = ""       '将引用来的外部变量置空
        
        ReDim wstr(5)  '给动态数组从新分配容量---大小为5
            
            
        wstr(0) = ">"  '赋值
            
        wstr(1) = " <"
            
        wstr(2) = ">="
            
        wstr(3) = " <="
            
        wstr(4) = "!="
            For i = LBound(wstr, 1) To UBound(wstr, 1)      ' 遍历动态数组数组wstr的第一维数据
        
      If InStr(1, CStr(ChkStr), wstr(i)) = 0 Then
      
      '判断对应数组中的值是否存在于chkstr中====》根据你此处的判断,要求输入的chkstr中一定要同时包含五个值!!
            
                ErrWord = wstr(i)   '首次检测到没有的放入errword
                
                StrCheck1 = False   '置错
                
                Exit For            '跳出
                
            End If
            
        Next iEnd Function
      

  3.   

    ReDim wstr(5)  '给动态数组从新分配容量---大小为5For i = LBound(wstr, 1) To UBound(wstr, 1)      ' 遍历动态数组数组wstr的第一维数据我是新手,请问下既然动太数组都重定义,且指定了其大小,为什么后面的FOR不直接用数字表示而还要去检测数组呢?是不是有点多余?
    呵呵,我是新手,刚学VB不久.让大家见笑了.