Home AMX User Forum NetLinx Studio
Options

Array element initialisation.

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,

Comments

  • Options
    BigsquatchBigsquatch Posts: 216
    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,


    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
    DEFINE_CONSTANT
    
    nMaxZones = 4
    
    DEFINE_VARIABLE
    
    _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
    
    
  • Options
    Jeff LockyearJeff Lockyear Posts: 147
    I originally had a constant, but then I couldn't change it based on user (installer) input. Could I somehow define the uZoneInfo array size after runtime?
  • Options
    mpullinmpullin Posts: 949
    I originally had a constant, but then I couldn't change it based on user (installer) input. Could I somehow define the uZoneInfo array size after runtime?
    Maximum length can't be changed at runtime (not in this language). If you really need to be able to change the length of the array when security zones are added/subtracted (how often does this happen?) without recompiling, I'd say just set nMaxZones to 64.
  • Options
    Jeff LockyearJeff Lockyear Posts: 147
    Zones won't change per system, but they will at each implementation of the module. I'm the only Programmer here, but we have a couple of installers who could send a command to the virtual to change max. zones for new systems; so I'm really trying to standardize my modules. It's no big deal, but I was wondering why I couldn't do it. I'll just set the variable to the maximum and bask in the glory of having lots of memory....

    Thanks for your help, guys.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    If you really must have different array sizes, set them as a CONSTANT in an include file the module reads. It will have to be re-compiled though for each implementation; no sending just a tok file on that one. I used to do it that way on a regular basis, but decided the annoyance of having to recompile all the time far offset the memory savings in a environment where I didn't really need to worry about memory.
  • Options
    Jeff LockyearJeff Lockyear Posts: 147
    Yeah, that really doesn't seem worth it. Another arrow in the quiver if needed though, thanks.
Sign In or Register to comment.