Option Explicit
Private Sub Picture1_Click()
Form1.WindowState = 1
End Sub
Private Sub Command1_Click()
Text1.Text = ""
End Sub
Private Sub Command3_Click()
RichTextBox1.Text = ""
End Sub
Private Sub Command4_Click()
Text2.Text = ""
End Sub
Private Sub Command2_Click()
'检验
RichTextBox1.Text = ""
Dim count1 As Long, count2 As Long 'count1对的次数,count2错的次数
Dim ary1, ary2 '存放分割后的数组
Dim ok
ok = False
For j = 0 To UBound(ary1)
If ary2(i) = ary1(j) Then
ok = True
Exit For
End If
Next
If ok = True Then
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelText = ary2(i) & vbTab & "正确" & vbCrLf
count1 = count1 + 1
Else
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelColor = vbRed
RichTextBox1.SelText = ary2(i) & vbTab & "错误" & vbCrLf
RichTextBox1.SelColor = vbBlack
count2 = count2 + 1
End If
Next
Label2 = count1
Label4 = count2
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyA And Shift = vbCtrlMask Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End If
End Sub
Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyA And Shift = vbCtrlMask Then
Text2.SelStart = 0
Text2.SelLength = Len(Text2)
End If
End Sub
Sub TextComp()
Const sTxt1$ = "abc,efg,ijk,lmn"
Const sTxt2$ = "abc,efg,lmn,opq,xyz,998"
Dim sPat$, i&
sPat = Replace(sTxt1, ",", "|")
Dim oRE As New RegExp ' 引用 Microsoft VBScript Regular Expressions 5.5
With oRE
.Global = True
.Pattern = sPat
With .Execute(sTxt2)
Debug.Print "正确次数:" & .Count
For i = 0 To .Count - 1
Debug.Print .Item(i) ' 依次输出 正确的内容
Next
End With
End With
目测一下,你的目的是判断“大底2”里面的数字是否在“大底1”里面存在是吧?
然后“大底1”与“大底2”的数字均为4位数。
再来,看见你有Split(Text1.Text, vbCrLf),可假设文件内每行一个数字,之后换行才是下一个数字
故而
Option Explicit
dim ary(10000) as long
dim i as long
dim intStr as string
for i=1 to 10000
ary(i)=0
next
Open "大底1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, intStr
ary(val(intStr)) = 1
Loop
Close #1
Open "大底2.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, intStr
ary(val(intStr)) = ary(val(intStr)) +1
Loop
Close #1
for i=1 to 10000
if ary(i)>0 then
txtResult = txtResult + str(i) + vbLFCR //i为大底1内与大底2内相同的数的值
next