Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Deleting Records?


Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2000, 11:30 AM
kingesk
Guest
 
Posts: n/a
Question Deleting Records?


'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


Reply With Quote
  #2  
Old 09-15-2000, 12:09 PM
kugela
Guest
 
Posts: n/a
Default Re: Deleting Records?

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
Reply With Quote
  #3  
Old 09-15-2000, 12:41 PM
kingesk
Guest
 
Posts: n/a
Default Re: Deleting Records?

That was simple enough. I don't know how I missed that.

Thanks,

Eric

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->