Dim MeRecord As Record Dim aaaa As Record1 Dim i, w, j As Integer RecordLen1 = Len(MeRecord) dim lon as long dim long1 as long Open App.Path & "\1.dat" For Binary Access Read As #2 '######## ( 1 ) Open App.Path & "\学生.dat" For Binary Access Read Write As #1 '######## ( 2 ) lon = LOF(1) / Len(aaaa); '######## ( 3 ) lon1 = LOF(2) / Len(MeRecord) '######## ( 4 ) With MSFlexGrid1 .Rows = 1 .Cols = 5 .TextMatrix(0, 0) = "" .TextMatrix(0, 1) = "" .TextMatrix(0, 2) = "" .TextMatrix(0, 3) = "" .TextMatrix(0, 4) = "" For j = 1 To lon Get #1, , aaaa .Rows = .Rows + 1 .TextMatrix(.Rows - 1, 0) = StrConv(aaaa.XM, vbUnicode) .TextMatrix(.Rows - 1, 1) = StrConv(aaaa.bj, vbUnicode) For i = 1 To lon2 Get #2, , MeRecord If StrConv(MeRecord.DM, vbUnicode) = StrConv(aaaa.XM, vbUnicode) .TextMatrix(.Rows - 1, 2) = MeRecord.date .TextMatrix(.Rows - 1, 3) = MeRecord.a1 .TextMatrix(.Rows - 1, 4) = MeRecord.a2 End If Next i Next j End With Close #2 Close #1
数组求教!!! '把符合D1日期的数据读入到一个数组中(GGG()),求教如何做,谢谢!!!! Private Type Record DM(1 To 3) As Byte MNAME(1 To 3) As Byte date As Long a1 As Long a2 As Long a3 As Long End Type Sub aaaa() Dim aa() As Record Dim BB() As Record Dim recordReal As Record Dim aaaa As Record1 Dim RecordLen As Long Dim MaxRecords As Long Dim ZHRQ As Long Dim i As Integer On Error Resume Next Open App.Path & "\1.dad" For Binary Access Read Write As #1 RecordLen = Len(recordReal) MaxRecords = LOF(1) / RecordLen ReDim aa(MaxRecords) Get #1, 1, aa(0) ZHRQ = aa(i).date For i = 0 To MaxRecords - 1 Get #1, 1 + i * RecordLen, aa(i) ZHRQ = IIf(MAXDATE >= aa(i).date, MAXDATE, aa(i).date) D1.Value = CDate(Format(ZHRQ, "####-##-##")) Next 'If D1 = CDate(Format(BB(i).date, "####-##-##")) Then '把符合D1日期的数据读入到一个数组中(GGG()),求教如何做,谢谢!!!!Close #1 End Sub
Dim aaaa As Record1
Dim i, w, j As Integer RecordLen1 = Len(MeRecord)
dim lon as long
dim long1 as long
Open App.Path & "\1.dat" For Binary Access Read As #2 '######## ( 1 )
Open App.Path & "\学生.dat" For Binary Access Read Write As #1 '######## ( 2 )
lon = LOF(1) / Len(aaaa); '######## ( 3 )
lon1 = LOF(2) / Len(MeRecord) '######## ( 4 )
With MSFlexGrid1
.Rows = 1
.Cols = 5
.TextMatrix(0, 0) = ""
.TextMatrix(0, 1) = ""
.TextMatrix(0, 2) = ""
.TextMatrix(0, 3) = ""
.TextMatrix(0, 4) = ""
For j = 1 To lon
Get #1, , aaaa
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 0) = StrConv(aaaa.XM, vbUnicode)
.TextMatrix(.Rows - 1, 1) = StrConv(aaaa.bj, vbUnicode)
For i = 1 To lon2
Get #2, , MeRecord
If StrConv(MeRecord.DM, vbUnicode) = StrConv(aaaa.XM, vbUnicode)
.TextMatrix(.Rows - 1, 2) = MeRecord.date
.TextMatrix(.Rows - 1, 3) = MeRecord.a1
.TextMatrix(.Rows - 1, 4) = MeRecord.a2
End If
Next i
Next j
End With
Close #2
Close #1
1)如果数据量较大时,请在填充数据前设置MSFlexGrid.Visible=False
完成后MSFlexGrid.Visible=True,这样会有很明显的速度改善
2)最好你能用数组把所有记录一次读出,前提条件是你必须知道整个文件中记录
的数量 (用Lof(#1)/len(Myrecord)).这样同样能把速度提高很多
'把符合D1日期的数据读入到一个数组中(GGG()),求教如何做,谢谢!!!!
Private Type Record
DM(1 To 3) As Byte
MNAME(1 To 3) As Byte
date As Long
a1 As Long
a2 As Long
a3 As Long
End Type
Sub aaaa()
Dim aa() As Record
Dim BB() As Record
Dim recordReal As Record
Dim aaaa As Record1
Dim RecordLen As Long
Dim MaxRecords As Long
Dim ZHRQ As Long
Dim i As Integer
On Error Resume Next
Open App.Path & "\1.dad" For Binary Access Read Write As #1
RecordLen = Len(recordReal)
MaxRecords = LOF(1) / RecordLen
ReDim aa(MaxRecords)
Get #1, 1, aa(0)
ZHRQ = aa(i).date
For i = 0 To MaxRecords - 1
Get #1, 1 + i * RecordLen, aa(i)
ZHRQ = IIf(MAXDATE >= aa(i).date, MAXDATE, aa(i).date)
D1.Value = CDate(Format(ZHRQ, "####-##-##"))
Next
'If D1 = CDate(Format(BB(i).date, "####-##-##")) Then
'把符合D1日期的数据读入到一个数组中(GGG()),求教如何做,谢谢!!!!Close #1
End Sub