This file is based on binary, maximum feature, using the long-type array, using the 32 system's most good data type, and the speed is significantly faster than the Byte array.
Option Explicit Private CencelCopy As Boolean Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long) Private Sub Command1_Click () Dim Pos As Long Command1.Enabled = False Command2.Enabled = True Pos = compfile (text1.text, text2.text) Command1.enabled = true command2.enabled = false select case pos case -2 msgbox "file not exist" case -1 msgbox "User Cancel" case 1 msgbox "len error" Case 0 MsgBox "Compare OK" Case Else MsgBox "Compare Fail in" & Pos End SELECT End Sub Private Function Compfile (File1 AS String, File2 AS STRING) AS Long Dim I As Long, K as Long Dim Pos AS Long, Eventsnum As Long Dim Fileno As INTEGER, Fileno1 As INTEGER, FileLast () AS BYTE, FILELAST1 () AS BYTE DIM Alllen As LONG, Onelen As INTEGER, BUFLEN As Long () As long, buf1 () as long buflen = 8192 onelen = 4 'Byte alignment' DIM BUF () AS BYTE, BUF1 () AS BYTE 'BUFLEN = 25600' Onelen = 1 DIM T as Single T = Timer - 0.1 'Reduced 0.1 is a zero error in preventing measurement operations, and can also eliminate point cache on speed IF (File1) = "" or Dir File2) = "" OR file1 = "" or file2 = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "
Lof (Fileno) POS = 1 Eventsnum = 1 fileno1 = freefile open file2 for binary access = 1) <> allleno1) <> alllen compfile = 1: Goto Ext Redim BUF (Buff1 - 1) Redim BUF1 (BUFLEN - 1 ) Do While POS BUFLEN * Onelen - 1 <= alllen get #fileno, BUF GET # fileno1, buf1 fork = 0 to Ubound (buf) IF BUF (K) <> buf1 (k) Then compfile = POS K * Onelen 'Redim Filelast (3)' If you want to accurately locate the differences in which byte, add this paragraph 'Redim Filelast1 (3)' CopyMemory FileLast (0), BUF (K), 4 'CopyMemory FilelasT1 (0 BUF1 (K), 4 ' For i = 0 to 3 'IFLAST (i) <> filelast1 (i) THEN EXIT for' Next 'compfile = compfile i goto ext end if next if Eventsnum mod 10 = 0 THEN CLS Print Pos, Round (Timer - T , 2), ROUND ((POS / (Timer - T)) / 1024, 2) & "KB / S"