473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 1922
"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 add ERR.Description to my code it fails on Syntax...
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 developer, but improved upon code and flow, etc. ...
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 together I usually consolidate the error handling...
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 IDisposable.Dispose, especially in a class that manages...
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 which is being listened for in a bit of code that then...
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. I need some way to reduce the width of the...
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 do 2 things with items displayed within the one...
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 *)malloc(strlen(s)+1); if( p != NULL) strcpy(p,s):...
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 construct, are difficult to use correctly,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.