VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 4395 ClientLeft = 60 ClientTop = 450 ClientWidth = 7575 LinkTopic = "Form1" ScaleHeight = 4395 ScaleWidth = 7575 StartUpPosition = 3 '窗口缺省 Begin VB.CheckBox Check1 Caption = "Find Next" Height = 375 Left = 3690 TabIndex = 6 Top = 2190 Width = 2295 End Begin VB.CommandButton Command1 Caption = "Command1" Height = 885 Left = 3540 TabIndex = 5 Top = 900 Width = 2205 End Begin VB.TextBox Text1 Height = 585 Index = 4 Left = 300 TabIndex = 4 Text = "Text1" Top = 3420 Width = 2955 End Begin VB.TextBox Text1 Height = 585 Index = 3 Left = 300 TabIndex = 3 Text = "Text1" Top = 2670 Width = 2955 End Begin VB.TextBox Text1 Height = 585 Index = 2 Left = 300 TabIndex = 2 Text = "Text1" Top = 1830 Width = 2955 End Begin VB.TextBox Text1 Height = 585 Index = 1 Left = 300 TabIndex = 1 Text = "Text1" Top = 990 Width = 2955 End Begin VB.TextBox Text1 Height = 585 Index = 0 Left = 330 TabIndex = 0 Text = "Text1" Top = 90 Width = 2955 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False '先将此5个TEXTBOX设定为控件数组(0~4) '添加一个Check1 '添加Command1 Dim FindNext As Boolean Private Sub Check1_Click() FindNext = IIf(Check1.Value = 1, True, False) End Sub Private Sub Command1_Click() Dim i&, j& Dim iTemp(9) As String, iCount& i = 0 j = 1 iCount = 0 Do While Text1(i) <> Text1(j) Or FindNext Or Not FindNext If Text1(i) = Text1(j) Then iTemp(iCount) = i & "," & j iCount = iCount + 1 If Not FindNext Then Exit Do End If If j < 4 Then j = j + 1 'If j = 4 And 1 Then Else i = i + 1 j = i + 1 If i = 4 Then Exit Do End If Loop Dim iFound& For i = 0 To 9 If iTemp(i) <> "" Then iFound = InStr(iTemp(i), ",") Debug.Print "序号:[" & Mid(iTemp(i), 1, iFound - 1) & "] -> 序号:[" & Mid(iTemp(i), iFound + 1, Len(iTemp(i))) & "] 相同" End If Next End Sub Private Sub Form_Load() FindNext = False End Sub
Dim i As Integer, j As Integer '说明,我是那个text控件定义成数组使用了 '如果你没有这么定义,那就定义一个数组, '把各个控件的值赋给数组,把下面的替换一下。 For i = 0 To 5 For j = 0 To 5
If i <> j Then If Text1(i).Text = Text1(j).Text Then ' 在这里写出如果两个内容相同了的事件代码
End If End If Next j
Next i本回答被网友采纳
第2个回答 2012-07-05
这个可以赋这五个值在一个1到5的数组a()中,可以用循环语句较行两两比较, for i =1 to 5 for j= i+1 to 5 if a(i)= a(j) then print a(i),a(j) ,i,j next j next i 这样就可以将相同的打印出来,就这样方法可以找出来,具体你要进行怎样的下一步不知道是什么....就只有这样,请采纳追问
如果初始五个数不是在文本中,而是在前一步生成的数列中,怎么做呢?
追答
哈哈,做任务的,就到此了,另请高手吧
第3个回答 2012-07-17
楼上的已经是很好的方法了 ---- for i =1 to 5 for j= i+1 to 5 if a(i)= a(j) then print a(i),a(j) ,i,j next j next i ----