G
Geoff Edwards
I do not understand how the following code can fail to work when
writing the first entry in a file. It defines the length of the
record by reference to the object being written, so how can the fail
with a "bad record length"?
This is the relevant code:
Rem If the record doesn't exist to overwrite, then it must
Rem be the first entry in a new database, or a new entry to
Rem add at the end of an old database
CurrentPFDataBaseRecNo = LocatePFRecord(ThisPFRecord.Name)
If CurrentPFDataBaseRecNo = 0 Then
If Dir(CurrentPFDatabaseFile) <> "" Then
CurrentPFDataBaseRecNo = (FileLen(CurrentPFDatabaseFile) /
Len(ThisPFRecord)) + 1
Else
CurrentPFDataBaseRecNo = 1
End If
End If
Dim ff1 As Integer
ff1 = FreeFile
Open CurrentPFDatabaseFile For Random As #ff1 Len =
Len(ThisPFRecord)
Put #ff1, CurrentPFDataBaseRecNo, ThisPFRecord
Close #ff1
I have checked that LocatePFRecord is returning as 0 (the search is
another procedure that I needn't bother you with).
I have also checked that by the time it gets to the offending line
CurrentPFDataBaseRecNo is indeed 1 as it should be.
The code is crashing at the line:
Put #ff1, CurrentPFDataBaseRecNo, ThisPFRecord
with the error "bad record length".
How can that be when it is the first entry in the file, and the length
is defined by the object itself?
Incidentally, ThisPFRecord is an instance of a user defined object
ProForma, and the type ProForma is made up of several other user
defined types. I have checked (double-checked and triple checked!)
that everything within those types is defined as Integer, Boolean or a
fixed-length string.
I am tearing my hair out here and any assistance would be greatly
appreciated.
Geoff
Geoff Edwards
Leeds, UK
e-mail: (e-mail address removed)
(replace the stopspambot bit with some
version of my name)
writing the first entry in a file. It defines the length of the
record by reference to the object being written, so how can the fail
with a "bad record length"?
This is the relevant code:
Rem If the record doesn't exist to overwrite, then it must
Rem be the first entry in a new database, or a new entry to
Rem add at the end of an old database
CurrentPFDataBaseRecNo = LocatePFRecord(ThisPFRecord.Name)
If CurrentPFDataBaseRecNo = 0 Then
If Dir(CurrentPFDatabaseFile) <> "" Then
CurrentPFDataBaseRecNo = (FileLen(CurrentPFDatabaseFile) /
Len(ThisPFRecord)) + 1
Else
CurrentPFDataBaseRecNo = 1
End If
End If
Dim ff1 As Integer
ff1 = FreeFile
Open CurrentPFDatabaseFile For Random As #ff1 Len =
Len(ThisPFRecord)
Put #ff1, CurrentPFDataBaseRecNo, ThisPFRecord
Close #ff1
I have checked that LocatePFRecord is returning as 0 (the search is
another procedure that I needn't bother you with).
I have also checked that by the time it gets to the offending line
CurrentPFDataBaseRecNo is indeed 1 as it should be.
The code is crashing at the line:
Put #ff1, CurrentPFDataBaseRecNo, ThisPFRecord
with the error "bad record length".
How can that be when it is the first entry in the file, and the length
is defined by the object itself?
Incidentally, ThisPFRecord is an instance of a user defined object
ProForma, and the type ProForma is made up of several other user
defined types. I have checked (double-checked and triple checked!)
that everything within those types is defined as Integer, Boolean or a
fixed-length string.
I am tearing my hair out here and any assistance would be greatly
appreciated.
Geoff
Geoff Edwards
Leeds, UK
e-mail: (e-mail address removed)
(replace the stopspambot bit with some
version of my name)