Sequential file record layout in VB.Net

  • Thread starter Thread starter Dan McGuffin
  • Start date Start date
D

Dan McGuffin

My understanding is that VB.Net does NOT support fixed string lengths. In
the past, in VB6, we could implement a record layout of a sequential input
file by creating a UDT (user-defined type) comprised of fixed length
strings. We are now converting our batch interface COBOL programs to VB.Net
console applications, and would like to know if there is a better way of
accessing the data fields on our sequential input file other than using a
whole bunch of 'Substring' statements.

Thanks,
Dan
 
* "Dan McGuffin said:
My understanding is that VB.Net does NOT support fixed string lengths. In
the past, in VB6, we could implement a record layout of a sequential input
file by creating a UDT (user-defined type) comprised of fixed length
strings. We are now converting our batch interface COBOL programs to VB.Net
console applications, and would like to know if there is a better way of
accessing the data fields on our sequential input file other than using a
whole bunch of 'Substring' statements.

Have a look at the 'VBFixedStringAttribute' class.
 
Hi Dan,

Have also a look at Herfrieds, favorite the MID function.
Mostly is that very efficient for this problem.

I hope this helps,

Cor
 
I've looked at that, but I don't think it helps. According to the VB.Net
help,

"Note The VBFixedStringAttribute is informational and cannot be used to
convert a variable length string to a fixed string. The purpose of this
attribute is to modify how strings in structures and non-local variables are
used by methods or API calls that recognize the VBFixedStringAttribute. Keep
in mind that this attribute does not change the actual length of the string
itself."

I want to be able to create a structure that I can lay a sequential record
over, then be able to access all of the specific fields within the
structure.

Dan
 
The MID function is pretty much the same as the Substring method; you still
need to know the starting position and length of each individual field in
the record. So, if one field changes size, the starting position of each
field after it changes. Using Mid and/or Substring to read fields off of a
sequential record leads to very measy code.

Dan
 
Dan McGuffin said:
In the past, in VB6, we could implement a record layout of a
sequential input file by creating a UDT (user-defined type) comprised
of fixed length strings.

Goodbye UDT - Hello Class.

I'd suggest you create a "Record" Class that wraps up a single file
record. It will have Read[Line] and Write[Line] methods for the file
I/O and Properties for every field in the [physical] record. This Class
takes responsibility for controlling the [un-]padding of data within fields
and can do any Type conversions at the same time, where it's convenient
to do so.

OK, within this Class, you're going to be doing quite a bit of
SubString'ing, but it's neatly self-contained so, having written (and
tested) it once, you don't really have to worry about it.

HTH,
Phill W.
 
you still
need to know the starting position and length of each individual field in
the record. So, if one field changes size, the starting position of each
field after it changes.

Where you talking about Cobol

Common Bussines Oriented Language or is it another Cobol you where talking
about?

Cor
 
Back
Top