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

Arrays inside of structs

Can someone help me out as to how to declare the Alarm array

Thanks
Ken
private void button1_Click(object sender, System.EventArgs e)
{
//
DCconfig.Ndata Dc = new DCconfig.Ndata();

Dc.System.ComPorts.Port1.DataBits = 7; // this works

Dc.Alarms.Alarm[0].Channel = 1; // this throws
System.NullReferenceException
}

namespace DCconfig
{
public class Cdata
{
public struct SysT
{
public string ConfigVersion;
public string FirmwareVirsion;
public string RecorderModel;
public string RecorderUnitTag;
public bool Beeper;

public struct ComP
{
public ComPortSpace.ComPorts Port1,Port2, Port3;
}
public ComP ComPorts;
}
public SysT System;
//-------------------------- system
end

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
}
public AlrM Alarms;
//--------------------------- end
alarms

}

public class Ndata
{
public Cdata.SysT System;
public Cdata.AlrM Alarms;
}

}
//----------------------------------------------
namespace AlarmSpace
{

public struct AlarmData
{
public bool Enable;
public bool Notify;
public byte Channel;
public string Type;
public float SetPoint;
public float DeadBand;
public uint Delay;
public uint Contact;
public struct EvntM
{
public bool Enable;
public string Message;
}
public EvntM EventMsg;

}

}
Nov 16 '05 #1
2 1755
Ken,

You declared a reference of an array but didn't create the array itself.

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
public AlrM(int num)
{
Alarm = new AlarmSpace.AlarmData[num];
}
}

Hope this helps..

Sam

"Ken Beauchesne" <kb*********@monarchinstrument.com> wrote in message
news:uo**************@TK2MSFTNGP15.phx.gbl...
Can someone help me out as to how to declare the Alarm array

Thanks
Ken
private void button1_Click(object sender, System.EventArgs e)
{
//
DCconfig.Ndata Dc = new DCconfig.Ndata();

Dc.System.ComPorts.Port1.DataBits = 7; // this works

Dc.Alarms.Alarm[0].Channel = 1; // this throws
System.NullReferenceException
}

namespace DCconfig
{
public class Cdata
{
public struct SysT
{
public string ConfigVersion;
public string FirmwareVirsion;
public string RecorderModel;
public string RecorderUnitTag;
public bool Beeper;

public struct ComP
{
public ComPortSpace.ComPorts Port1,Port2, Port3;
}
public ComP ComPorts;
}
public SysT System;
//-------------------------- system
end

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
}
public AlrM Alarms;
//--------------------------- end
alarms

}

public class Ndata
{
public Cdata.SysT System;
public Cdata.AlrM Alarms;
}

}
//----------------------------------------------
namespace AlarmSpace
{

public struct AlarmData
{
public bool Enable;
public bool Notify;
public byte Channel;
public string Type;
public float SetPoint;
public float DeadBand;
public uint Delay;
public uint Contact;
public struct EvntM
{
public bool Enable;
public string Message;
}
public EvntM EventMsg;

}

}

Nov 16 '05 #2
Thanks

Ken
"Sam Sungshik Kong" <ss*@chol.nospam.net> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
Ken,

You declared a reference of an array but didn't create the array itself.

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
public AlrM(int num)
{
Alarm = new AlarmSpace.AlarmData[num];
}
}

Hope this helps..

Sam

"Ken Beauchesne" <kb*********@monarchinstrument.com> wrote in message
news:uo**************@TK2MSFTNGP15.phx.gbl...
Can someone help me out as to how to declare the Alarm array

Thanks
Ken
private void button1_Click(object sender, System.EventArgs e)
{
//
DCconfig.Ndata Dc = new DCconfig.Ndata();

Dc.System.ComPorts.Port1.DataBits = 7; // this works

Dc.Alarms.Alarm[0].Channel = 1; // this throws
System.NullReferenceException
}

namespace DCconfig
{
public class Cdata
{
public struct SysT
{
public string ConfigVersion;
public string FirmwareVirsion;
public string RecorderModel;
public string RecorderUnitTag;
public bool Beeper;

public struct ComP
{
public ComPortSpace.ComPorts Port1,Port2, Port3;
}
public ComP ComPorts;
}
public SysT System;
//-------------------------- system end

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
}
public AlrM Alarms;
//--------------------------- end
alarms

}

public class Ndata
{
public Cdata.SysT System;
public Cdata.AlrM Alarms;
}

}
//----------------------------------------------
namespace AlarmSpace
{

public struct AlarmData
{
public bool Enable;
public bool Notify;
public byte Channel;
public string Type;
public float SetPoint;
public float DeadBand;
public uint Delay;
public uint Contact;
public struct EvntM
{
public bool Enable;
public string Message;
}
public EvntM EventMsg;

}

}


Nov 16 '05 #3

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

Similar topics

1
by: Dave A | last post by:
The following C code specifies the interface into a DLL. I need to access it from C#. How do I do declare it? I have done simple ones before but this particular API requires a pointer to a struct...
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: Gomaw Beoyr | last post by:
Hello Is there any explanation why Microsoft chose to implement arrays as objects allocated on the heap instead of structs allocated on the stack? For "mathematical stuff", one normally...
33
by: Peter Seaman | last post by:
I understand that structures are value types and arrays and classes are reference types. But what about arrays as members of structures i.e. as in C struct x { int n; int a; }
1
by: Raj | last post by:
Hi, This is regarding using Arrays of UDT's in COM. The following is a short description: - We basically need a structure, struct MAIN_STRUCT which must contain a dynamic array of another...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
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...
3
by: Zenon | last post by:
I have a function which returns array of structs. I need to create a collection of those arrays and thought that an ArrayList would be a good way to do this since the count is variable. The...
127
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.