给定一组数据,如1234567、1233567、7654321、7664321
假设1 2 3 4的查询码是1,5 6 7的查询码是2
那么给定任意查询数码,如1111222,则查询结果为1234567、1233567。
其实就是模式匹配的问题吧,急!!!!!!!!!!!!!!

解决方案 »

  1.   

    保存到数组里 
    先把数据保存在一个临时数组里和原始数组一一对应
    把临时数组里的数据 用一大堆的 
    ss = Replace(ss, "2", "1")
    ss = Replace(ss, "3", "1")
    之类的代码  替换掉这样不就可以直接用=查到了吗?
      

  2.   


    Option Explicit'一个查询码只配置一个字符吗?如果这样就好解决了。
    Private Sub Command1_Click()
      Dim A(2) As String
      A(0) = "11234" '表示1可以配置 1234
      A(1) = "456"   '表示4可以配置 56
      A(2) = "37"    '表示3可以配置 7
      
      MsgBox curFind("2341765", "1111344", A)'返回True表示配置成功.
    End Sub
    'Txt 是要配置的字符串, FindTxt是查询码.
    'Arr是要配置的查询码数组
    '我设定的格式 Arr(1)="11245" 表示 1可以配置1245
    '我设定的格式 Arr(1)="2567" 表示 2可以配置567
    '数组第一位表示配置符,后面跟着的表示可以配置的字符
    '数组的起始位置为0Public Function curFind(ByVal Txt As String, ByVal FindTxt As String, ByVal Arr) As Boolean
       curFind = True
       Dim i As Long
       Dim j As Long
       Dim Index As Long
       Index = -1
       
       If Len(Txt) <> Len(FindTxt) Then
         curFind = False
         Exit Function
       End If
       For i = 1 To Len(Txt)
          For j = 0 To UBound(Arr)
             If InStr(1, Arr(j), Mid(FindTxt, i, 1)) = 1 Then
               Index = j
               Exit For
             End If
          Next
          
          If Index = -1 Then
             curFind = False
             Exit Function
          End If
          
          If InStr(1, Mid(Arr(Index), 2), Mid(Txt, i, 1)) = 0 Then
              curFind = False
              Exit Function
          End If
       Next
       
    End Function
      

  3.   

    帮你写了段代码 
    相信你一看就明白了 
    Dim a(3)
    Dim S1
    Dim S
    a(0) = "1234567"
    a(1) = "1233567"
    a(2) = "7654321"
    a(3) = "7664321"
    S1 = InputBox("输入")
    For i = 0 To 3
        S = a(i)
        S = Replace(S, "2", "1")
        S = Replace(S, "3", "1")
        S = Replace(S, "4", "1")
        S = Replace(S, "5", "2")
        S = Replace(S, "6", "2")
        S = Replace(S, "7", "2")
        If S = S1 Then MsgBox  a(i)
    Next
      

  4.   

    我也写一个,用Like操作符
    Dim arr(0 To 9) As String
    Private Sub Form_Load()
        arr(0) = ""
        arr(1) = "1234" '1234的查询码是1
        arr(2) = "567"   '567的查询码是2
        arr(3) = ""
        arr(4) = ""
        arr(5) = ""
        arr(6) = ""
        arr(7) = ""
        arr(8) = ""
        arr(9) = ""
    End Sub's 是要核对的数据  t是一串查询码
    Private Function Fun1(ByVal S As String, ByVal t As String) As Boolean
        Dim x As String
        Dim i As Long
        For i = 1 To Len(t)
            x = x & "[" & arr(Asc(Mid(t, i)) - 48) & "]"
        Next
        Fun1 = S Like x
    End FunctionPrivate Sub Command1_Click()
        Dim a(3)
        a(0) = "1234567"
        a(1) = "1233567"
        a(2) = "7654321"
        a(3) = "7664321"
        For i = 0 To 3
            If Fun1(a(i), "1111222") Then
                Print a(i)
            End If
        Next
    End Sub
      

  5.   

    没必要限定查询码的为纯数字
    Option ExplicitSub Main()
        Dim a(), sPattern As String, i As Long
        
        a = Array("1234567", "1233567", "7654321", "7664321")
        sPattern = MakePattern("1111222")
        
        For i = LBound(a) To UBound(a)
            If a(i) Like sPattern Then Debug.Print a(i)
        Next
    End SubFunction MakePattern(ByVal CheckCode As String) As String
        Dim sReturn As String, i As Long
        
        For i = 1 To Len(CheckCode)
            Select Case Mid$(CheckCode, i, 1)
                Case "1":   sReturn = sReturn & "[1-4]"
                Case "2":   sReturn = sReturn & "[5-7]"
                '可以按规则任意扩充
                Case Else:  Debug.Assert False
            End Select
        Next
        
        MakePattern = sReturn
    End Function
      

  6.   

    那么应该反向考虑,对数据进行预处理,求出每组数的 hash 值:
    data    hash
    ------- -------
    1234567 1111222
    1233567 1111222
    7654321 2221111
    7664321 2221111
    ------- -------
    再给 hash 字段建立索引,查询就很方便了。
      

  7.   

    死机是因为没加doevents吧...
    还是那句,想简单快捷就用正则表达式.