现有一textbox控件组,共八个,每一个都是只能输入八个字符,如何做到:当往任意两个textbox输入相同的字符串之后,弹出提示对话框,同时将后输入的textbox中的内容清空。
请高手指点迷津。感激涕零啊!vb textbox控件组

解决方案 »

  1.   


    Private Sub Text1_Change(Index As Integer)
    Dim i As Integer    If Len(Text1(Index)) = 8 And Index > 0 Then
            For i = 0 To Index - 1
                If Text1(Index) = Text1(i) Then
                    MsgBox "Repeated information"
                    Text1(Index) = ""
                End If
            Next i
        End If
    End Sub
      

  2.   

    首先,多谢英雄赐教,不过我试运行了一下,发现有点瑕疵:我先在Text1(0)输入八位字符串,然后在Text1(7)输入相同的字符串,如愿的弹出对话框,但是要“确定”7次才能把对话框关闭,不知道能不能琢磨成一块美玉呢?
      

  3.   


    Private Sub Text1_Change(Index As Integer)
      If Len(Text1(Index).Text) <> 8 Then Exit Sub
      Dim vI As Integer
      For vI = 0 To 7
        If Index <> vI And Text1(Index).Text = Text1(vI).Text Then
          MsgBox "重复"
          Text1(Index).Text = ""
          Exit For
        End If
      Next
    End Sub
      

  4.   

    原因是其他文本框为空,而 Text1(7) 清空后与它们相同。如果不是顺序输入的话:Private Sub Text1_Change(Index As Integer)
    Dim i As Integer    If Len(Text1(Index)) = Text1(Index).MaxLength Then
            For i = 0 To Text1.Count - 1
                If i <> Index And Text1(Index) = Text1(i) Then
                    MsgBox "Repeated information"
                    Text1(Index) = ""
                    Exit Sub
                End If
            Next i
        End If
    End Sub