473,388 Members | 1,399 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,388 software developers and data experts.

Structure ?

I want to be able to create a structure like I did in VB6, that have
variables

Name As String * 10
Age As String * 3

for the size of the strings. Can I do this some way in VB.net?

I'm playing with <StructLayoutArribute()and <MarshalAs()attributes, but
I'm not really wanting to expose these structrues to COM. I only want to use
them inside VB.net assemblies.

Help!

JerryM
Feb 19 '07 #1
11 2794
"JerryWEC" <Je******@newsgroups.nospamschrieb:
>I want to be able to create a structure like I did in VB6, that have
variables

Name As String * 10
Age As String * 3

for the size of the strings. Can I do this some way in VB.net?
This syntax is not supported any more. You can mimick it using the
'VBFixedStringAttribute' attribute. However, if you are converting the
assembly from VB6 to VB.NET, I'd rethink the design. You could implement
'Name' and 'Age' as properties and pad the string to the desired length in
the property's 'Set' accessor.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 19 '07 #2
On the 16th Feb. Jerry someone asked the same sort of question in this
newsgroup. It was posted by 'Rick Knospler' & the subject was 'VB6
Conversion. Need help understanding how to implement fixed length string
arrays..'

In this post you will have your answer

--
Newbie Coder
(It's just a name)
Feb 19 '07 #3
Herfried, this is a good idea... It is new code and I was hoping there was
a way to simulate the old way of doing strings for fixed size. Seems like
the new Structure object is overkill and should have had this fixed string
capability built in.

I'm still thinking a structure is still faster than a class since it's
stored on the stack?

TIA! JerryM
Feb 19 '07 #4
JerryM,

The .Net Framework Developer's Guide gives the following recommendations on
when to use a structure vs a class:

Do not define a structure unless the type has all of the following
characteristics:

It logically represents a single value, similar to primitive types (integer,
double, and so on).

It has an instance size smaller than 16 bytes.

It is immutable.

It will not have to be boxed frequently.

If one or more of these conditions are not met, create a reference type
instead of a structure. Failure to adhere to this guideline can negatively
impact performance.

Kerry Moorman

"JerryWEC" wrote:
Herfried, this is a good idea... It is new code and I was hoping there was
a way to simulate the old way of doing strings for fixed size. Seems like
the new Structure object is overkill and should have had this fixed string
capability built in.

I'm still thinking a structure is still faster than a class since it's
stored on the stack?

TIA! JerryM
Feb 19 '07 #5
Kerry, thanks for the tip!

Where can I find this .Net Framework Developer's Guide? Is this an online
document or is it in msdn?

Thanks! JerryM
Feb 19 '07 #6
JerryM,

When I choose Help | Index from the Visual Basic 2005 Express Edition IDE
and look for "structure" I get a long list of references. One reference is
under "structures [.Net Framework] and is titled "design guidelines". When I
choose "design guidelines" I get a document headed ".NET Framework
Developer's Guide".

So I guess this developer's guide is somehow part of the online
documentation. I don't know if it can be browsed as an independent document.

Kerry Moorman
"JerryWEC" wrote:
Kerry, thanks for the tip!

Where can I find this .Net Framework Developer's Guide? Is this an online
document or is it in msdn?

Thanks! JerryM
Feb 19 '07 #7
yes; you are correct in your analysis.

UNECESSARY CHANGE IS NOT WANTED
UNECESSARY CHANGE IS NOT BEING ACCEPTED IN THE MARKET
UNECESSARY CHANGE IS NOT SEXY

On Feb 19, 7:57 am, "JerryWEC" <Jerry...@newsgroups.nospamwrote:
Herfried, this is a good idea... It is new code and I was hoping there was
a way to simulate the old way of doing strings for fixed size. Seems like
the new Structure object is overkill and should have had this fixed string
capability built in.

I'm still thinking a structure is still faster than a class since it's
stored on the stack?

TIA! JerryM

Feb 19 '07 #8
Most of MS documentation is available on the web:

http://msdn2.microsoft.com/en-us/library/ms229017.aspx

Kerry Moorman wrote:
JerryM,

When I choose Help | Index from the Visual Basic 2005 Express Edition IDE
and look for "structure" I get a long list of references. One reference is
under "structures [.Net Framework] and is titled "design guidelines". When I
choose "design guidelines" I get a document headed ".NET Framework
Developer's Guide".

So I guess this developer's guide is somehow part of the online
documentation. I don't know if it can be browsed as an independent document.

Kerry Moorman
"JerryWEC" wrote:
>Kerry, thanks for the tip!

Where can I find this .Net Framework Developer's Guide? Is this an online
document or is it in msdn?

Thanks! JerryM

--
Göran Andersson
_____
http://www.guffa.com
Feb 19 '07 #9
Göran, thanks for the refer link!

I have created two classes on called WeldData and one called WeldInterval.
I have an array of WeldInterval's in my WeldData class.

I have not been able to test this because I'm in assembly /.dll hell again
right now.

I really just wanted to create a structure to hold my data and beable to
create empty records and build more data related records as needed. I have
490 bytes of data in a record and did not want to create a full blown class
or classes. I'm working in a manufacturing environment and speed is
everything. I'm hoping this will be fast enough for plant floor operation.

I'll provided more feedback if these two classes don't work as I expect them
too.

thanks! JerryM
Feb 19 '07 #10
JerryM,

You might also want to consider using a List (Of WeldInterval) instead of an
array in your WeldData class.

Kerry Moorman
"JerryWEC" wrote:
Göran, thanks for the refer link!

I have created two classes on called WeldData and one called WeldInterval.
I have an array of WeldInterval's in my WeldData class.

I have not been able to test this because I'm in assembly /.dll hell again
right now.

I really just wanted to create a structure to hold my data and beable to
create empty records and build more data related records as needed. I have
490 bytes of data in a record and did not want to create a full blown class
or classes. I'm working in a manufacturing environment and speed is
everything. I'm hoping this will be fast enough for plant floor operation.

I'll provided more feedback if these two classes don't work as I expect them
too.

thanks! JerryM
Feb 19 '07 #11
JerryWEC wrote:
Göran, thanks for the refer link!

I have created two classes on called WeldData and one called WeldInterval.
I have an array of WeldInterval's in my WeldData class.

I have not been able to test this because I'm in assembly /.dll hell again
right now.

I really just wanted to create a structure to hold my data and beable to
create empty records and build more data related records as needed. I have
490 bytes of data in a record and did not want to create a full blown class
or classes. I'm working in a manufacturing environment and speed is
everything. I'm hoping this will be fast enough for plant floor operation.

I'll provided more feedback if these two classes don't work as I expect them
too.

thanks! JerryM

Don't be afraid to create a class. If your data consists of strings,
then you are using objects anyway, so there is no real gain in using a
structure to handle them.

Objects are a lot faster in .NET than in VB6. I remember seeing a test
that showed that .NET handled objects about 100 times faster. Even if
that test might not be representative for all aspects of object use, you
get an idea of the difference in speed.

As the guidelines states, structures should only be used for data that
represent a single value. Also it says that a reasonable size for a
structure is 16 bytes. If you have 490 bytes in a structure, you will
get a performance hit everytime you use the structure. As it's passed by
value, all 490 bytes will be copied every time.

Also structures are value types, and that may cause you some problems.
If your WeldInterval is a structure and you access one of them from the
array, it will be copied. If you change a property in the structure you
might expect that you are changing the data in your array, but that
doesn't happen, as you are working with a copy of the data.
--
Göran Andersson
_____
http://www.guffa.com
Feb 20 '07 #12

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

Similar topics

2
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
4
by: marco_segurini | last post by:
Hi, From my VB program I call a C++ function that gets a structure pointer like parameter. The structure has a field that contains the structure length and other fields. My problem is that...
8
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. ...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
3
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String...
14
by: Dennis | last post by:
If I have a structure like; Public Structure myStructureDef Public b() as Byte Public t as String End Structure If I pass this structure, will the values in the array b be stored on the...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
11
by: Lance | last post by:
Hi all, I've got a some structures defined as ////// <StructLayout(LayoutKind.Sequential)Public Structure GM_LayerInfo_t Public mDescription As String Public mNativeRect As GM_Rectangle_t...
4
by: eBob.com | last post by:
In my class which contains the code for my worker thread I have ... Public MustInherit Class Base_Miner #Region " Delegates for accessing main UI form " Delegate Sub DelegAddProgressBar(ByVal...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.