472,353 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Handling fixed-length strings in Visual Basic.NET

I have had to move to Visual Studio.NET Pro. from Visual Basic 4.0 and am now starting to re-write our code. I was a bit surprised to find that Visual Basic.NET no longer supports fixed length strings, which is a pain as we use our own database format with specific, user-defined data types and random access files. An example module content would be

Option Explici
Type Record
Operation As String * 4
unit As String * 2
Marker1 As String *
Size As Intege
Material As String * 1
Massaverage As Doubl
Trippage As Intege
ProductionTotal As Doubl
country As String *
region As String * 1
Year As Intege
End Typ

Type Record
a(1 To 10) As String * 4
m(1 To 10) As Doubl
e(1 To 10, 1 To 3) As Doubl
l(1 To 10) As Intege
End Typ

I would very much appreciate any tips on how I can recode the above data types so that Visual Basic.NET can read existing data files created using these data types

Many thanks in advance for any replies.
Nov 20 '05 #1
4 1840
"LCAdeveloper" <an*******@discussions.microsoft.com> schrieb
I have had to move to Visual Studio.NET Pro. from Visual Basic 4.0
and am now starting to re-write our code. I was a bit surprised to
find that Visual Basic.NET no longer supports fixed length strings,
which is a pain as we use our own database format with specific,
user-defined data types and random access files. An example module
content would be:

Option Explicit
Type Record1
Operation As String * 41
unit As String * 25
Marker1 As String * 1
Size As Integer
Material As String * 10
Massaverage As Double
Trippage As Integer
ProductionTotal As Double
country As String * 3
region As String * 10
Year As Integer
End Type

Type Record2
a(1 To 10) As String * 40
m(1 To 10) As Double
e(1 To 10, 1 To 3) As Double
l(1 To 10) As Integer
End Type

I would very much appreciate any tips on how I can recode the above
data types so that Visual Basic.NET can read existing data files
created using these data types.


Have a look at
Microsoft.VisualBasic.VBFixedArrayAttribute
Microsoft.VisualBasic.VBFixedStringAttribute

These are only relevant when using the VB file I/O functions (fileopen,
fileget ...)

Attributes in general:
http://msdn.microsoft.com/library/en...Attributes.asp

http://msdn.microsoft.com/library/en...attributes.asp
Very important for upgrading in general:
http://msdn.microsoft.com/library/en...ualBasic60.asp
especially sub topic "Introduction to Visual Basic .NET for Visual Basic
Veterans"

and
http://msdn.microsoft.com/library/en...nVB6AndVB7.asp

especially concerning your question:
http://msdn.microsoft.com/library/en...ringLength.asp

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

"LCAdeveloper" <an*******@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
our own database format with specific, user-defined data types
and random access files. An example module content would be:

.. . .

Fixed Length Strings are only available through a Compatibility
library which, although it will work perfectly well, is only provided
by Our Friends in Redmond as a "crutch" so that VB [Proper]
Developers can keep their existing code running [that is until they
learn how to do things the "new" way]. ;-)

I would recommend replacing your Types with Classes, and your
[Type] elements with Properties thereof. You then have a choice
- either fix the length of each data element in the Class instance
(a.k.a. Record) as you set each property, or add Read and Write
methods that interpret the physical file data into something easier
to handler in code (e.g. the Write method takes the [variable-
length] strings held within the Object and pads them as required
before writing them to the physical file).

HTH,
Phill W.
Nov 20 '05 #3
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> schrieb

"LCAdeveloper" <an*******@discussions.microsoft.com> wrote in
message news:0B**********************************@microsof t.com...
our own database format with specific, user-defined data types
and random access files. An example module content would be:

. . .

Fixed Length Strings are only available through a Compatibility
library which, although it will work perfectly well, is only
provided by Our Friends in Redmond as a "crutch" so that VB
[Proper] Developers can keep their existing code running [that is
until they learn how to do things the "new" way]. ;-)


This is wrong. The Compatibility library is a different one
(Microsoft.VisualBasic.Compatibility.dll: "Microsoft Visual Basic .NET
Compatibility Runtime"). The attributes are a part of the usual VB.Net
library (Microsoft.VisualBasic.dll: "Microsoft Visual Basic .NET Runtime").
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> schrieb

"LCAdeveloper" <an*******@discussions.microsoft.com> wrote in
message news:0B**********************************@microsof t.com...
our own database format with specific, user-defined data types
and random access files. An example module content would be:

. . .

Fixed Length Strings are only available through a Compatibility
library which, although it will work perfectly well, is only
provided by Our Friends in Redmond as a "crutch" so that VB
[Proper] Developers can keep their existing code running [that is
until they learn how to do things the "new" way]. ;-)


This is wrong. The Compatibility library is a different one
(Microsoft.VisualBasic.Compatibility.dll: "Microsoft Visual Basic .NET
Compatibility Runtime"). The attributes are a part of the usual VB.Net
library (Microsoft.VisualBasic.dll: "Microsoft Visual Basic .NET

Runtime").

Oops!!! You're quite right - My mistake.

Now; where /did/ I get idea from?

Apologies,
Phill W.
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: David | last post by:
Hello I am trying to collect errors and record them in a table instead of a popup message stopping my code. It seems to work ok, but when I try to...
5
by: james.igoe | last post by:
History: Took over development of Access project after half of app was developed. Continued the second half using same coding style as first...
13
by: Michael B Allen | last post by:
This is a highly opinionated question but I'd like to know what people think in this matter. When initializing / creating a group of objects...
0
by: Joe | last post by:
Reposting here as there were no useful replies in the dotnet.framework NG... What is the correct pattern for handling exceptions in...
1
by: Michael McCarthy | last post by:
I've written an event that tells me that I've connected properly to a remote telnet location. When I know that I'm connected I fire the event...
1
by: HoustonFreeways | last post by:
I am populating a dropdownlist via a databind to a database. However, the text to be displayed can be very long, making the dropdownlist very wide....
2
by: John Dann | last post by:
This question has arisen from an earlier thread but is really a separate issue: I have a VB.Net listbox control on a form. I want to be able to...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
94
by: Chad | last post by:
On to top of page 163 in the book "The C Programming Langauge" by K & R, they have the following: char *strdup(char *s) { char *p; p=(char...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.