by seabuck (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 13th September 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
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
' 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
No comments have been posted about sort user defined type binary file by a field then recreate file. Why not be the first to post a comment about sort user defined type binary file by a field then recreate file.