Code not working for deleting recordfrom a file

Reply

Join Date: May 2004
Posts: 2
Reputation: tubularowl is an unknown quantity at this point 
Solved Threads: 0
tubularowl tubularowl is offline Offline
Newbie Poster

Code not working for deleting recordfrom a file

 
0
  #1
May 11th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 40
Reputation: Buff is an unknown quantity at this point 
Solved Threads: 0
Buff Buff is offline Offline
Light Poster

Re: Code not working for deleting recordfrom a file

 
0
  #2
May 11th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 2
Reputation: tubularowl is an unknown quantity at this point 
Solved Threads: 0
tubularowl tubularowl is offline Offline
Newbie Poster

Re: Code not working for deleting recordfrom a file

 
0
  #3
May 18th, 2004
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC