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

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_MESSAGE {
//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_DATA */ {
unsigned char EventNumber; // (1-N, With 1 Being Most Recent)
unsigned char EventTimeDateValid;
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 EventParameter2High;
unsigned char EventParameter2Low;
};
struct /* olmCOMMAND_MESSAGE */ {
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_INFORMATION */ {
unsigned char ModelNumber;
unsigned char MajorVersion;
unsigned char MinorVersion;
unsigned char Revision;
unsigned char LocalPhoneNumber[25];
};
struct /* olmSYSTEM_STATUS */ {
unsigned char TimeDateValidFlag;
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 DaylightSavingsTimeFlag;
unsigned char CalculatedSunriseHour; // (0-23)
unsigned char CalculatedSunriseMinute; // (0-59)
unsigned char CalculatedSunsetHour; // (0-23)
unsigned char CalculatedSunsetMinute; // (0-59)
unsigned char BatteryReading;
unsigned char AreaSecurityMode[8]; // index 0-7
struct {
unsigned char Status;
unsigned char BatteryReading;
} ExpansionEnclosure[8]; // index 0-7
};
struct /* olmREQUEST_ZONE_STATUS */ {
unsigned char StartingZone;
unsigned char EndingZone;
};
struct /* olmZONE_STATUS */ {
unsigned char ZoneStatus;
unsigned char AnalogLoopReading;
} 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 CurrentCondition;
unsigned char HighByteOfTime;
unsigned char LowByteOfTime;
} Unit[84];
struct /* olmREQUEST_AUXILIARY_STATUS */ {
unsigned char StartingTemperatureSensor;
unsigned char EndingTemperatureSensor;
};
struct /* olmAUXILIARY_STATUS */ {
unsigned char RelayStatus;
unsigned char CurrentTemperature;
unsigned char LowHeatTemperatureSetpoint;
unsigned char HighCoolTemperatureSetpoint;
} TempSensor[63];
struct /* olmREQUEST_THERMOSTAT_STATUS */ {
unsigned char StartingThermostat;
unsigned char EndingThermostat;
};
struct /* olmTHERMOSTAT_STATUS */ {
unsigned char StatusByte;
unsigned char CurrentTemperature;
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_EVENTS */ {
unsigned char High;
unsigned char Low;
} SystemEvent[127];
struct /* olmMESSAGE_STATUS */ {
unsigned char Data;
} MessageStatus[33];
struct /* olmREQUEST_SECURITY_CODE_VALIDATION */ {
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_CODE_VALIDATION */ {
unsigned char UserCodeNumber; // (1-99, 251 for duress, 0 if
invalid)
unsigned char AuthorityLevel;
//(0=Invalid,1=Master,2=Manager,3=User)
};
}; // union
}; // struct
}; // union
};

Thanks,
Danny
Feb 7 '06 #1
9 8184
"Danny Mavromatis" <ne**@mavromatis.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=setscreenresolution&lang=en>.
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_MESSAGE {
//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(LayoutKind.Explicit)> _
Private Structure R_OMNI_LINK_MESSAGE
' 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**************@TK2MSFTNGP15.phx.gbl...
"Danny Mavromatis" <ne**@mavromatis.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=setscreenresolution&lang=en>.
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*@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.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_MESSAGE 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****************@TK2MSFTNGP11.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_MESSAGE 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****************@TK2MSFTNGP11.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******@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.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_MESSAGE 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****************@TK2MSFTNGP11.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
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...
8
by: Saïd | last post by:
Hi, If I define two structures like this struct s1 { int a; int b; }
1
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...
5
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
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 ...
1
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,...
12
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...
7
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
by: Ravikiran | last post by:
Hi, I want know the differences between Unions and Structures in C programming. Thank you..
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
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: 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
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.