Deleting Records?

kingesk
09-15-2000, 11:30 AM
'Deleting unwanted Records?

'I am reading in a file and wanting to output a file with
'only the records that do not have zero in the salary field.
'The logic I am using below works in the sense that
'it doesn't output a zero salary record but it then
'outputs the previous record twice. I also need to get rid
'of records with a duplicate SSN. Any ideas would be appreciated.

'Eric


intNumRecords = LOF(1) / Len(udtInputRecord)
For intIndex = 1 To intNumRecords
Get #1, intIndex, udtInputRecord

If udtInputRecord.strSalary <> 0 Then
udtoutputrecord.strFirst = udtInputRecord.strFirst
udtOutputRecord.strLast = udtInputRecord.strLast
udtoutputrecord.strSSN = udtInputRecord.strSSN
udtoutputrecord.strBirthDate = udtInputRecord.strBirthDate
udtoutputrecord.strMarriageDate = udtInputRecord.strMarriageDate
udtoutputrecord.strPad1 = udtInputRecord.strPad1
udtoutputrecord.strSalary = udtInputRecord.strSalary
udtoutputrecord.strDef = udtInputRecord.strDef
udtoutputrecord.strMatch = udtInputRecord.strMatch
udtoutputrecord.strLoan1 = udtInputRecord.strLoan1
udtoutputrecord.strLoan2 = udtInputRecord.strLoan2
udtoutputrecord.strPad2 = udtInputRecord.strPad2
udtoutputrecord.strStreet1 = udtInputRecord.strStreet1
udtoutputrecord.strStreet2 = udtInputRecord.strStreet2
udtoutputrecord.strCity = udtInputRecord.strCity
udtOutputRecord.strState = udtInputRecord.strState
udtoutputrecord.strZip = udtInputRecord.strZip
udtoutputrecord.strTermDate = udtInputRecord.strTermDate
udtoutputrecord.strBuffer = udtInputRecord.strBuffer
End If


'write output record to file
Put #2, intIndex, udtoutputrecord

kugela
09-15-2000, 12:09 PM
First Problem: How do you prevent a record from being written when the salary is 0.

This one is easy. Simply move the line...

Put #2, intIndex, udtoutputrecord

inside of the block-if statement. That is to say...

If salary is not 0, then write the record to file.
The reason that you get the previous record written twice when encountering a record with a 0 salary is that
1) as you code stands, you write to file in every iteration of the loop, and
2) because the code to change the output record to the current input record is contained within the block-if, that code does not get executed when the salary is 0, and, thus the previous record is the data stored in the output record.

The second problem is a bit more complex. If it is possible, I would recommend that you convert your data into a database, (Why not use Access?) and then use ADO to perform these functions. It probably would be a lot easier.

"It's COOL to say NO to Codeine-coated Land-mine Pops!" -Ruben Bolling

kingesk
09-15-2000, 12:41 PM
That was simple enough. I don't know how I missed that.

Thanks,

Eric

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum