[Year 12 Its] VB.NET record structure/random access file question

Frank Van Den Boom vandenboomfj at aquinas.vic.edu.au
Mon Jul 24 16:05:56 EST 2006


In my conversion from VB6 to VB.NET, I have hit a snag in the area of
random access file processing.
 
Here is what I am trying to do:
- create a record structure which has a mixture of field data types eg
	Structure CDType
		Dim ID As Short
		Dim Title As String
		Dim Artist As String
		Dim price As Decimal
	End Structure
- Assuming variable 'CD' is of type 'CDType, then open the file for
random access.
		FileOpen(1, filename, OpenMode.Random, , , Len(onecd))
- The program crashes ('bad record length') when I write new records to
the (using Fileput), where the string fields are longer than one
character.

What is really weird about this, is that it does not happen for all
users, which made me think it was security related. But PC's are all
ghosted with same setup, so I have put that possible cause on the
sideline for now.

I think the problem arises because of the way the String fields are
declared in the record structure.

In VB6, 'bad record length' also arose in this situation and it was
essential that String variables be followed by the number of characters
to allocate to that field. Eg.
	Structure CDType
		Dim ID As Short
		Dim Title As String * 15
		Dim Artist As String * 10
		Dim price As Decimal
	End Structure
 
And given the nature of random file processing, that made plenty of
sense to me. Unless it assumed that everyone string was 255 characters,
how else could it determine record length. However that VB6 syntax is
not accepted in VB.NET, and I have searched high and low for its
successor without success.

Any ideas out there?
Frank



More information about the is mailing list