Array element initialisation.
Jeff Lockyear
Posts: 147
If I do this:
DEFINE_VARIABLE
VOLATILE INTEGER nMaxZones = 4
_sSECURITY uZoneInfo[nMaxZones] // Structure _sSECURITY
DEFINE_START
uZoneInfo[1].sZoneName = 'Zone 1' // Line 191
uZoneInfo[2].sZoneName = 'Zone 2' // Line 192
uZoneInfo[3].sZoneName = 'Zone 3' // Line 193
uZoneInfo[4].sZoneName = 'Zone 4' // Line 194
I get this:
Starting NetLinx Compile - Version[2.5.1.10] [05-05-2009 09:33:46]
C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs
ERROR: C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs(192): C10611: Array index is out of bounds for dimension 1. Element 2 is not within defined bounds of 1..1
ERROR: C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs(193): C10611: Array index is out of bounds for dimension 1. Element 3 is not within defined bounds of 1..1
ERROR: C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs(194): C10611: Array index is out of bounds for dimension 1. Element 4 is not within defined bounds of 1..1
C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs - 3 error(s), 0 warning(s)
NetLinx Compile Complete [05-05-2009 09:33:46]
My module is working well otherwise, but I don't want to hard code the number of zones (I would rather use nMaxZones (initialized by the user or whatever)) nor just define uZoneInfo[64] if the system doesn't have 64 zones (the max possible).
Any reason I can't do what (I think) I want to? Do I bite the memory bullet and just define uZoneInfo as having 64 elements?
Cheers,
DEFINE_VARIABLE
VOLATILE INTEGER nMaxZones = 4
_sSECURITY uZoneInfo[nMaxZones] // Structure _sSECURITY
DEFINE_START
uZoneInfo[1].sZoneName = 'Zone 1' // Line 191
uZoneInfo[2].sZoneName = 'Zone 2' // Line 192
uZoneInfo[3].sZoneName = 'Zone 3' // Line 193
uZoneInfo[4].sZoneName = 'Zone 4' // Line 194
I get this:
Starting NetLinx Compile - Version[2.5.1.10] [05-05-2009 09:33:46]
C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs
ERROR: C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs(192): C10611: Array index is out of bounds for dimension 1. Element 2 is not within defined bounds of 1..1
ERROR: C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs(193): C10611: Array index is out of bounds for dimension 1. Element 3 is not within defined bounds of 1..1
ERROR: C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs(194): C10611: Array index is out of bounds for dimension 1. Element 4 is not within defined bounds of 1..1
C:\NETLINX ARCHIVE\_More\MODULES\Jeff Modules\DSC\DSC 5401 Comm rev1.axs - 3 error(s), 0 warning(s)
NetLinx Compile Complete [05-05-2009 09:33:46]
My module is working well otherwise, but I don't want to hard code the number of zones (I would rather use nMaxZones (initialized by the user or whatever)) nor just define uZoneInfo[64] if the system doesn't have 64 zones (the max possible).
Any reason I can't do what (I think) I want to? Do I bite the memory bullet and just define uZoneInfo as having 64 elements?
Cheers,
0
Comments
I think the problem is that you are not using a constant to declare your array. Arrays are allocated at compile time and at compile the value of nMaxZones will be 0.
Try
Thanks for your help, guys.