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

Alex Hopkins a.hopkins at bcc.vic.edu.au
Mon Jul 24 16:57:51 EST 2006


Hi Frank,

I suspect you're right.  Try something like the following:

    Structure Person

        Public ID As Integer

        Public MonthlySalary As Decimal

        Public LastReviewDate As Date

        <VBFixedString(15)> Public FirstName As String

        <VBFixedString(15)> Public LastName As String

        <VBFixedString(15)> Public Title As String

        <VBFixedString(150)> Public ReviewComments As String

    End Structure

The key element is the <VBFixedString(x)> (not the Public).  I have a working example if that would help.

-Alex Hopkins, Bayside Christian College



----- Original Message ----- 
From: "Frank Van Den Boom" <vandenboomfj at aquinas.vic.edu.au>
To: <is at edulists.com.au>
Sent: Monday, July 24, 2006 4:05 PM
Subject: [Year 12 Its] VB.NET record structure/random access file question


> 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
> 
> _______________________________________________
> http://www.edulists.com.au
> IT Systems Mailing List kindly supported by
> http://www.vcaa.vic.edu.au - Victorian Curriculum and Assessment Authority and
> http://www.vitta.org.au  - VITTA Victorian Information Technology Teachers Association Inc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/is/attachments/20060724/f811d81e/attachment.html


More information about the is mailing list