| | |
Code not working for deleting recordfrom a file
![]() |
•
•
Join Date: May 2004
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: May 2004
Posts: 40
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- Does this code working after changing environment? (VB.NET)
- I would liike to multiply two matrices but my code is not working..help me out! (C++)
- Reading and Writing file (C)
- conversion of text file into data base file (Visual Basic 4 / 5 / 6)
- Deleting a record from a file (C)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: ODBC has encountered a problem and needs to close
- Next Thread: Macros in Excel
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





