Home AMX User Forum NetLinx Studio

Error with Structure Array

All:

I've added a structure, then tried to create an array based on that structure. On compile I get: Symbol [ROOMARRAY] already defined in scope.

Here's my code
DEFINE_TYPE

STRUCTURE sRoomInfo
{
    CHAR LongName [40]
    CHAR ShortName [40]
    CHAR IPAddress [40]
}

DEFINE_VARIABLE

sRoomInfo RoomArray[4]

RoomArray[1].LongName  = 'Living Room'
RoomArray[1].ShortName  =  'LR'
RoomArray[1].IPAddress  = '192.168.1.100'

RoomArray[2].LongName  = Kitchen'
RoomArray[2].ShortName  = 'K'
RoomArray[2].IPAddress  = '192.168.1.101'

RoomArray[3].LongName  = 'Bedroom 1'
RoomArray[3].ShortName  = 'BR 1'
RoomArray[3].IPAddress  = '192.168.1.200'

RoomArray[4].LongName  = 'Bedroom 1'
RoomArray[4].ShortName  = 'BR2'
RoomArray[4].IPAddress  = '192.168.1.201'



This seems to be the syntax in the help file. However, the file also mentions the array and elements should be in braces. I've tried several variations of braces, but then I get an "Initializer is not a constant" error.

TIA for any help.
Norm

Comments

  • ericmedleyericmedley Posts: 4,177
    normschaef wrote: »
    All:

    I've added a structure, then tried to create an array based on that structure. On compile I get: Symbol [ROOMARRAY] already defined in scope.

    Here's my code
    DEFINE_TYPE
    
    STRUCTURE sRoomInfo
    {
    CHAR LongName [40]
    CHAR ShortName [40]
    CHAR IPAddress [40]
    }
    
    DEFINE_VARIABLE
    
    sRoomInfo RoomArray[4]
    
    RoomArray[1].LongName = 'Living Room'
    RoomArray[1].ShortName = 'LR'
    RoomArray[1].IPAddress = '192.168.1.100'
    
    RoomArray[2].LongName = Kitchen'
    RoomArray[2].ShortName = 'K'
    RoomArray[2].IPAddress = '192.168.1.101'
    
    RoomArray[3].LongName = 'Bedroom 1'
    RoomArray[3].ShortName = 'BR 1'
    RoomArray[3].IPAddress = '192.168.1.200'
    
    RoomArray[4].LongName = 'Bedroom 1'
    RoomArray[4].ShortName = 'BR2'
    RoomArray[4].IPAddress = '192.168.1.201'
    
    
    

    This seems to be the syntax in the help file. However, the file also mentions the array and elements should be in braces. I've tried several variations of braces, but then I get an "Initializer is not a constant" error.

    TIA for any help.
    Norm

    Hi Norm!

    this section of code is the problem:
    RoomArray[1].LongName = 'Living Room'
    RoomArray[1].ShortName = 'LR'
    RoomArray[1].IPAddress = '192.168.1.100'
    
    RoomArray[2].LongName = Kitchen'
    RoomArray[2].ShortName = 'K'
    RoomArray[2].IPAddress = '192.168.1.101'
    
    RoomArray[3].LongName = 'Bedroom 1'
    RoomArray[3].ShortName = 'BR 1'
    RoomArray[3].IPAddress = '192.168.1.200'
    
    RoomArray[4].LongName = 'Bedroom 1'
    RoomArray[4].ShortName = 'BR2'
    RoomArray[4].IPAddress = '192.168.1.201'
    
    

    essnetially you are trying to re-define the variable.

    The easiest way to keep what you have and not have to retype like crazy is to just put the code in the DEFINE_START section.
    DEFINE_START
    RoomArray[1].LongName = 'Living Room'
    RoomArray[1].ShortName = 'LR'
    RoomArray[1].IPAddress = '192.168.1.100'
    
    RoomArray[2].LongName = Kitchen'
    RoomArray[2].ShortName = 'K'
    RoomArray[2].IPAddress = '192.168.1.101'
    
    RoomArray[3].LongName = 'Bedroom 1'
    RoomArray[3].ShortName = 'BR 1'
    RoomArray[3].IPAddress = '192.168.1.200'
    
    RoomArray[4].LongName = 'Bedroom 1'
    RoomArray[4].ShortName = 'BR2'
    RoomArray[4].IPAddress = '192.168.1.201'
    
  • normschaefnormschaef Posts: 17
    Eric

    In this case, I couldn't trust the documentation ....

    Thanks for setting me on the straight and narrow.
    Norm
  • ericmedleyericmedley Posts: 4,177
    yeah, it's a good idea to read it first. But, it doesn't always turn out to be true. If you get into a snag iwht it, you know my number. e
Sign In or Register to comment.