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