473,549 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET Structures and Union Help.

I have a chunk of VC.NET code (below) that I need to convert to VB.NET
syntax. Could someone help me get started? I'm new to structures and
unions and I don't understand how to nest then in VB.NET.

' ----- VC.NET CODE THAT I NEED TO CONVERT TO VB.NET ----

struct R_OMNI_LINK_MES SAGE {
//unsigned char StartChar;
unsigned char MessageLength;
union {
unsigned char Data[255];
struct {
unsigned char MessageType;
union {
struct /* olmNAME_DATA (8 bit) */ {
unsigned char ItemType8;
unsigned char ItemNumber8;
unsigned char ItemName8[16];
};
struct /* olmNAME_DATA (16 bit) */ {
unsigned char ItemType16;
unsigned char ItemNumber16MSB ;
unsigned char ItemNumber16LSB ;
unsigned char ItemName16[16];
};
struct /* olmEVENT_LOG_DA TA */ {
unsigned char EventNumber; // (1-N, With 1 Being Most Recent)
unsigned char EventTimeDateVa lid;
unsigned char EventMonth; // (1-12)
unsigned char EventDay; // (1-31)
unsigned char EventHour; // (0-23)
unsigned char EventMinute; // (0-59)
unsigned char EventType;
unsigned char EventParameter1 ;
unsigned char EventParameter2 High;
unsigned char EventParameter2 Low;
};
struct /* olmCOMMAND_MESS AGE */ {
unsigned char Command;
unsigned char Parameter1;
unsigned char Parameter2High;
unsigned char Parameter2Low;
};
struct /* olmSET_TIME */ {
unsigned char stYear;
unsigned char stMonth;
unsigned char stDay;
unsigned char stDOW;
unsigned char stHour;
unsigned char stMinute;
unsigned char stDST;
};
struct /* olmSYSTEM_INFOR MATION */ {
unsigned char ModelNumber;
unsigned char MajorVersion;
unsigned char MinorVersion;
unsigned char Revision;
unsigned char LocalPhoneNumbe r[25];
};
struct /* olmSYSTEM_STATU S */ {
unsigned char TimeDateValidFl ag;
unsigned char Year; // (0-99)
unsigned char Month; // (1-12)
unsigned char Day; // (1-31)
unsigned char DayOfWeek; // (1-7)
unsigned char Hour; // (0-23)
unsigned char Minute; // (0-59)
unsigned char Second; // (0-59)
unsigned char DaylightSavings TimeFlag;
unsigned char CalculatedSunri seHour; // (0-23)
unsigned char CalculatedSunri seMinute; // (0-59)
unsigned char CalculatedSunse tHour; // (0-23)
unsigned char CalculatedSunse tMinute; // (0-59)
unsigned char BatteryReading;
unsigned char AreaSecurityMod e[8]; // index 0-7
struct {
unsigned char Status;
unsigned char BatteryReading;
} ExpansionEnclos ure[8]; // index 0-7
};
struct /* olmREQUEST_ZONE _STATUS */ {
unsigned char StartingZone;
unsigned char EndingZone;
};
struct /* olmZONE_STATUS */ {
unsigned char ZoneStatus;
unsigned char AnalogLoopReadi ng;
} Zone[127];
struct /* olmREQUEST_UNIT _STATUS (8 bit) */ {
unsigned char StartingUnit;
unsigned char EndingUnit;
};
struct /* olmREQUEST_UNIT _STATUS (16 bit) */ {
unsigned char StartingUnitMSB ;
unsigned char StartingUnitLSB ;
unsigned char EndingUnitMSB;
unsigned char EndingUnitLSB;
};
struct /* olmUNIT_STATUS */ {
unsigned char CurrentConditio n;
unsigned char HighByteOfTime;
unsigned char LowByteOfTime;
} Unit[84];
struct /* olmREQUEST_AUXI LIARY_STATUS */ {
unsigned char StartingTempera tureSensor;
unsigned char EndingTemperatu reSensor;
};
struct /* olmAUXILIARY_ST ATUS */ {
unsigned char RelayStatus;
unsigned char CurrentTemperat ure;
unsigned char LowHeatTemperat ureSetpoint;
unsigned char HighCoolTempera tureSetpoint;
} TempSensor[63];
struct /* olmREQUEST_THER MOSTAT_STATUS */ {
unsigned char StartingThermos tat;
unsigned char EndingThermosta t;
};
struct /* olmTHERMOSTAT_S TATUS */ {
unsigned char StatusByte;
unsigned char CurrentTemperat ure;
unsigned char HeatSetpoint;
unsigned char CoolSetpoint;
unsigned char SystemMode;
unsigned char FanMode;
unsigned char HoldStatus;
} Thermostat[36];
struct /* olmLOGIN */ {
unsigned char LoginCode1;
unsigned char LoginCode2;
unsigned char LoginCode3;
unsigned char LoginCode4;
};
struct /* olmSYSTEM_EVENT S */ {
unsigned char High;
unsigned char Low;
} SystemEvent[127];
struct /* olmMESSAGE_STAT US */ {
unsigned char Data;
} MessageStatus[33];
struct /* olmREQUEST_SECU RITY_CODE_VALID ATION */ {
unsigned char AreaNumber; // (1-8)
unsigned char Code1; // First Digit Of Code
unsigned char Code2; // Second Digit Of Code
unsigned char Code3; // Third Digit Of Code
unsigned char Code4; // Fourth Digit Of Code
};
struct /* olmSECURITY_COD E_VALIDATION */ {
unsigned char UserCodeNumber; // (1-99, 251 for duress, 0 if
invalid)
unsigned char AuthorityLevel;
//(0=Invalid,1=Ma ster,2=Manager, 3=User)
};
}; // union
}; // struct
}; // union
};

Thanks,
Danny
Feb 7 '06 #1
9 8200
"Danny Mavromatis" <ne**@mavromati s.com> schrieb:
I have a chunk of VC.NET code (below) that I need to convert to VB.NET
syntax. Could someone help me get started? I'm new to structures and
unions and I don't understand how to nest then in VB.NET.


You can simulate unions using the 'FieldOffset' attribute as shown in the
sample at
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=setscreenre solution&lang=e n>.
VB.NET doesn't support unions in its syntax directly.

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

Feb 7 '06 #2
Herfried,

Thanks for the quick reply... however, looking at the example, I'm a bit
confused...

Lets say I have the following from VC.NET:

struct R_OMNI_LINK_MES SAGE {
//unsigned char StartChar;
unsigned char MessageLength;
union {
unsigned char Data[255];
struct {
unsigned char MessageType;
union {
struct /* olmNAME_DATA (8 bit) */ {
unsigned char ItemType8;
unsigned char ItemNumber8;
unsigned char ItemName8[16];
};
struct /* olmNAME_DATA (16 bit) */ {
unsigned char ItemType16;
unsigned char ItemNumber16MSB ;
unsigned char ItemNumber16LSB ;
unsigned char ItemName16[16];
};
}; // union
}; // struct
}; // union
};
I would have the following in VB.NET???:

<StructLayout(L ayoutKind.Expli cit)> _
Private Structure R_OMNI_LINK_MES SAGE
' struct {
<FieldOffset(0) > Public MessageLength As Integer
<FieldOffset(2) > Public MessageType As Char
<FieldOffset(4) > Public ItemType8 As Char
<FieldOffset(6) > Public ItemNumber8 As Char
' }
End Structure
I'm not understanding the concept... could someone help me get started with
the code I have? So I can visually see how to do it with my code.

Thanks,
Danny

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:eB******** ******@TK2MSFTN GP15.phx.gbl...
"Danny Mavromatis" <ne**@mavromati s.com> schrieb:
I have a chunk of VC.NET code (below) that I need to convert to VB.NET
syntax. Could someone help me get started? I'm new to structures and
unions and I don't understand how to nest then in VB.NET.


You can simulate unions using the 'FieldOffset' attribute as shown in the
sample at
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=setscreenre solution&lang=e n>.
VB.NET doesn't support unions in its syntax directly.

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

Feb 7 '06 #3
Danny,

You know that converting direct from one language to another gives forever
terrible code. The first time I saw this was in the Cobol Fortran battle
time.

Somebody usually writing Fortran had showed how much inefficient
instructions were needed to do a sort in Cobol, while he could done it clean
in Fortran.

He did not know that Sort is in Cobol one method.

Cor
Feb 7 '06 #4
guy
Cor, you are showing your age;-)
its a bit like rewriting an 8080 block copy into Z80 instead of using the
intrinsic LDIR opcode. That dates me too lol

*guy*

"Cor Ligthert [MVP]" wrote:
Danny,

You know that converting direct from one language to another gives forever
terrible code. The first time I saw this was in the Cobol Fortran battle
time.

Somebody usually writing Fortran had showed how much inefficient
instructions were needed to do a sort in Cobol, while he could done it clean
in Fortran.

He did not know that Sort is in Cobol one method.

Cor

Feb 7 '06 #5
So are you guys saying it's not possible? The reason why I need to convert
to VB.NET is because the provider of the DLL doesn't have an example for
VB.NET so, I'm trying to make it work with my application... everything else
I rewrote and is working... I'm just stuck on the unions and structures.
It's something that I haven't ever been exposed to in VB.NET. So I was
asking for some help... I take it that it's more difficuilt to do unions and
structures in VB.net than it is writting a reply that doesn't really help,
otherwise, someone would have provided some example code with my example, to
help me on my way.

"guy" <gu*@discussion s.microsoft.com > wrote in message
news:87******** *************** ***********@mic rosoft.com...
Cor, you are showing your age;-)
its a bit like rewriting an 8080 block copy into Z80 instead of using the
intrinsic LDIR opcode. That dates me too lol

*guy*

"Cor Ligthert [MVP]" wrote:
Danny,

You know that converting direct from one language to another gives
forever
terrible code. The first time I saw this was in the Cobol Fortran battle
time.

Somebody usually writing Fortran had showed how much inefficient
instructions were needed to do a sort in Cobol, while he could done it
clean
in Fortran.

He did not know that Sort is in Cobol one method.

Cor

Feb 7 '06 #6
Danny,

No that is not what we are writing. We try to tell you that it is better to
analyze your problem than to take a piece of code from a not related
development tool.

If you decribe your problem than it is problably in newsgroups like this
easier to help you. Mostly you find it than yourself by the way.

I hope this helps,

Cor
Feb 7 '06 #7
Umm, no, the reason why I posted is because I have exhaused my resources and
this is my last resort.

What I need help with is this:

I have a record structure that comes in via WM_COPYDATA and I grab the
cbData (length of response message) and lpData (ptr to response message).
This data must be copied to local variables so I can access the data outside
of the WM_COPYDATA function. So, for ease of processing the cbData and
lpData, it can be moved into a R_OMNI_LINK_MES SAGE structure (which is the
where I'm stuck) where the fields can be referred to by name rather than
byte offset.

So, I'm trying to figure out a way to do this in VB.net... structures and
unions seem to make sense, since that is what they are designed for...
however, I don't know anything about them in VB.net... hence, me asking for
some help.

Danny

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Danny,

No that is not what we are writing. We try to tell you that it is better
to analyze your problem than to take a piece of code from a not related
development tool.

If you decribe your problem than it is problably in newsgroups like this
easier to help you. Mostly you find it than yourself by the way.

I hope this helps,

Cor

Feb 7 '06 #8
Maybe this link will help:

http://msdn.microsoft.com/library/de...uresunions.asp

"Danny Mavromatis" wrote:
Umm, no, the reason why I posted is because I have exhaused my resources and
this is my last resort.

What I need help with is this:

I have a record structure that comes in via WM_COPYDATA and I grab the
cbData (length of response message) and lpData (ptr to response message).
This data must be copied to local variables so I can access the data outside
of the WM_COPYDATA function. So, for ease of processing the cbData and
lpData, it can be moved into a R_OMNI_LINK_MES SAGE structure (which is the
where I'm stuck) where the fields can be referred to by name rather than
byte offset.

So, I'm trying to figure out a way to do this in VB.net... structures and
unions seem to make sense, since that is what they are designed for...
however, I don't know anything about them in VB.net... hence, me asking for
some help.

Danny

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Danny,

No that is not what we are writing. We try to tell you that it is better
to analyze your problem than to take a piece of code from a not related
development tool.

If you decribe your problem than it is problably in newsgroups like this
easier to help you. Mostly you find it than yourself by the way.

I hope this helps,

Cor


Feb 8 '06 #9
FYI: I've moved this discussion to another board where it's more helpful.

http://www.vbdotnetforums.com/showth...3724#post23724

"TrtnJohn" <Tr******@discu ssions.microsof t.com> wrote in message
news:9A******** *************** ***********@mic rosoft.com...
Maybe this link will help:

http://msdn.microsoft.com/library/de...uresunions.asp

"Danny Mavromatis" wrote:
Umm, no, the reason why I posted is because I have exhaused my resources
and
this is my last resort.

What I need help with is this:

I have a record structure that comes in via WM_COPYDATA and I grab the
cbData (length of response message) and lpData (ptr to response message).
This data must be copied to local variables so I can access the data
outside
of the WM_COPYDATA function. So, for ease of processing the cbData and
lpData, it can be moved into a R_OMNI_LINK_MES SAGE structure (which is
the
where I'm stuck) where the fields can be referred to by name rather than
byte offset.

So, I'm trying to figure out a way to do this in VB.net... structures and
unions seem to make sense, since that is what they are designed for...
however, I don't know anything about them in VB.net... hence, me asking
for
some help.

Danny

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
> Danny,
>
> No that is not what we are writing. We try to tell you that it is
> better
> to analyze your problem than to take a piece of code from a not related
> development tool.
>
> If you decribe your problem than it is problably in newsgroups like
> this
> easier to help you. Mostly you find it than yourself by the way.
>
> I hope this helps,
>
> Cor
>


Feb 8 '06 #10

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

Similar topics

14
3527
by: Peter Olcott | last post by:
I want to be able to efficiently build data structures at run-time. These data structures need to be accessed with minimal time. The only a few ways that come immediately to mind would be some sort of dynamically allocated array of : (1) void pointers, that must be cast into the desired types. (2) union of the desired pointers. (3) An...
8
1753
by: Saïd | last post by:
Hi, If I define two structures like this struct s1 { int a; int b; }
1
1149
by: asm | last post by:
Hi All, I would like to know what should be the criteria to choose between a union / structure. Also switch statement vs if - else. I know switch only 'switches' on integer types. Some example would be of help. Thanks, ASM
5
1898
by: Shwetabh | last post by:
Hi everyone. My question is, why are data structures implemented only with struct data type? Why not union when it is more efficient as compared with structures? Thanks in advance
2
1741
by: Vinay Kodam | last post by:
Hi all, I have a union with two structures in it as shown below. The source code is written in VC++. I want to represent the same in VB.Net. union { struct { LONG lMinimum; LONG lMaximum; };
1
2310
by: aarklon | last post by:
Hi folks, Recently i was reading the book C an advanced introduction by narain gehani, in page no:236 it is written as If a union contains several structures with a common initial sequence, then members of this sequence are guaranteed to have the same values and they can be
12
1995
by: addinall | last post by:
Hi guys and gals, Haven't been in here for a good decade or so! I'm having a braid-dead moment that is lasting for a couple of days. Declaring pointers to functions witrhin structures and accessing same.... This doesnt work. I thought it should. The compiler disagrees with me! gcc32
7
1516
by: blockstack | last post by:
I recently noticed (I'm new to the language) that when using a union type as a component of a structure, you don't need a union-tag. struct foo { char *ptr; union { int i; float f;
6
3681
by: Ravikiran | last post by:
Hi, I want know the differences between Unions and Structures in C programming. Thank you..
0
7524
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7960
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6048
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
766
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.