0
我有一個文件夾包含測試數據的.txt文件。我編寫了一個宏來篩選.txt文件,根據一些搜索條件提取我想要的信息,然後將這些搜索結果寫入二進制文件。從二進制文件導入數據非常慢
因此,現在我有一個包含簡化數據集的二進制文件,我編寫了另一個宏來搜索二進制文件以獲得我真正想要的內容。
出於某種原因,我的宏從二進制文件中讀取數據的速度很慢。
作爲比較,我寫了一個宏,查看所有txt文件中的特定搜索,將其寫入二進制文件,然後將其讀回Excel。那隻需要60秒。
這是一段代碼。我想知道if-else語句是否符合我的搜索條件[LC(a)和EID(e)]是否會降低速度或減小二進制文件大小(僅爲200 MB)。
Type MyBinaryRecordInfo
MyBinaryRecordInfo1(1 To 12) As String ' variable length
End Type
i = 1
Open currentpath & "\" & bin_fname & ".DAT" For Binary As #f
' read records from the binary file
For a = 1 To totalLC
For e = 1 To totalElm
Do While Loc(f) < LOF(f)
Call ReadBinRecord(MyRecord, f, ElmType)
Sheets(ElmType).Select
If MyRecord.MyBinaryRecordInfo1(1) = LC(a) Then
If MyRecord.MyBinaryRecordInfo1(2) = EID(e) Then
For j = 1 To totalbinrec
With MyRecord
Cells(i + 3, j) = .MyBinaryRecordInfo1(j)
End With
Next j
i = i + 1
Exit Do
End If
End If
Loop
Next e
Next a
Close #f ' close the file
Sub ReadBinRecord(MyRecord As MyBinaryRecordInfo, f As Integer, ElmType As String)
' reads the next record from an open binary file
Dim intSize As Integer
For j = 1 To totalbinrec
With MyRecord
Get f, , intSize ' read the size of the ID field
.MyBinaryRecordInfo1(j) = String(intSize, " ") ' set the variable length
Get f, , .MyBinaryRecordInfo1(j) ' read the variable string field
End With
Next j