sort user defined type binary file by a field then recreate file
sort user defined type binary file by a field then recreate file
API Declarations
Dim strPart(1 To 500) As String
Dim intNum As Integer
Dim intLastRecord As Integer
Dim blnFlag As Boolean
Dim gap As Integer
Dim index As Integer
Dim tempP As String
Dim tempR As Integer
Dim record As udtPartRecord
Dim x As Integer
Rate sort user defined type binary file by a field then recreate file
(1(1 Vote))
' bring in a (field) and a (binary file index field) into an array and sort by the field'
Call OpenFile Open Two files ( current and new ) same type and assignment
intLastRecord = LOF(1) \ Len(record) 'uesr defined type'
For intNum = 1 To intLastRecord
Get #3, intNum, record
intRec(intNum) = intNum
strPart(intNum) = record.strPartNum
Next intNum
'sort'
gap = (intLastRecord / 2)
Do While gap >= 1
Do
blnFlag = True
For index = 1 To intLastRecord - gap
If UCase(strPart(index)) < UCase(strPart(index + gap)) Then
'swap'
tempP = strPart(index)
strPart(index) = strPart(index + gap)
strPart(index + gap) = tempP
tempR = intRec(index)
intRec(index) = intRec(index + gap)
intRec(index + gap) = tempR
blnFlag = False
End If
Next index
Loop Until blnFlag = True
gap = Int(gap / 2)
Loop
For x = 1 To intLastRecord
Get #1, intRec(x), record
lblRecord.Caption = intRec(x) ' used to indicate total file completed'
Put #2, x, record
Next x
Call CloseFile
' delete the old file and rename the new file'
Kill "Partdata.iex"
Name "Partdata.new" As "Partdata.iex"
End Sub
sort user defined type binary file by a field then recreate file Comments
No comments yet — be the first to post one!
Post a Comment