943,832 Members | Top Members by Rank

Ad:
May 11th, 2004
0

Code not working for deleting recordfrom a file

Expand Post »
I'm trying to delete a single record from a rnd file using a delete button. On click the code below the problem seems to be with the keep statement. I keep getting a compile error:invalid qualifier on selectedbook even though the value matches the position of the record in the file. any ideas anyone ?


Dim newrecordcount As Integer 'New recordcount for updated records'
Dim Book As BookType 'Book as single record'
Dim BookArray() As BookType 'Book array = dynamic'
ReDim BookArray(1 To recordcount) 'Redefine array to recordcount'
Dim N As Integer 'Define loop variable'

selectedbook.keep = False 'flag book record to remove'

Open filename For Random As #1 Len = Len(Book) 'Open file'

For N = 1 To recordcount
Get #1, N, Book
If selectedbook = True Then 'populate array'
newrecordcount = newrecordcount + 1 'with records but flag'
BookArray(newrecordcount) = Book 'selectedbook as false'
End If
Next N
Close #1 'close file

Kill filename 'kill file'

The file can then be rewritten to the same file path.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tubularowl is offline Offline
2 posts
since May 2004
May 11th, 2004
0

Re: Code not working for deleting recordfrom a file

The easiest way to 'delete' a record in a random file is to write (put)
for RN&=Record&+1 to NR& (number of records)
Get #1,RN&,UDT
PUT #1,RN&-1,UDT
next

then have some way of controlling what the total records are (NR&) and reduce it by 1, such as a separate file containing the number of records or
as another UDT of the same length in Record 1 (so that the actual data
records exist in records 2 to NR&+1).

I do this as well as insert records in my Client Writeup for CPAs program.

If you clear the entire file, then you can rewrite records 1 to Record&-1
first.

UDT of course, stands for a User-defined Type.
in QB if you have a large file and are putting the entire UDT records in an array, you might run into memory problem. With PowerBasic for windows, you shouldn't have that problem.
Reputation Points: 11
Solved Threads: 0
Light Poster
Buff is offline Offline
40 posts
since May 2004
May 18th, 2004
0

Re: Code not working for deleting recordfrom a file

I was making a big mistake here by trying to make 'selectedbook' false when it contained a true variable, which is not possible in VB. The problem has been sorted now by doing as you mentioned, deleting the selected variable stringtype and rewriting the file. Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tubularowl is offline Offline
2 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: ODBC has encountered a problem and needs to close
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Macros in Excel





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC