Home AMX User Forum NetLinx Studio

Loading fixed data into a structure array

Hi,

I've got the following structure defined:

STRUCTURE _Button_Command
{
INTEGER Button_Number // Button number
CHAR Button_Command[20] // RS232 Command
}

_Button_Command _sButton_Command[]


Is there a shorthand method of loading fixed data into the structure array?

An example of the data I want to load is:

1 , $02,'3','0','0','5','A','2',$00,'1',$00,$03
2 , $02,'3','0','0','5','A','2',$00,'2',$00,$03
3 , $02,'3','0','0','5','A','2',$00,'3',$00,$03
4 , $02,'3','0','0','5','A','2',$00,'4',$00,$03
5 , $02,'3','0','0','5','A','2',$00,'5',$00,$03

Thanks for looking.

Steve

Comments

  • ericmedleyericmedley Posts: 4,177
    sijones wrote: »
    Hi,

    I've got the following structure defined:

    STRUCTURE _Button_Command
    {
    INTEGER Button_Number // Button number
    CHAR Button_Command[20] // RS232 Command
    }

    _Button_Command _sButton_Command[]


    Is there a shorthand method of loading fixed data into the structure array?

    An example of the data I want to load is:

    1 , $02,'3','0','0','5','A','2',$00,'1',$00,$03
    2 , $02,'3','0','0','5','A','2',$00,'2',$00,$03
    3 , $02,'3','0','0','5','A','2',$00,'3',$00,$03
    4 , $02,'3','0','0','5','A','2',$00,'4',$00,$03
    5 , $02,'3','0','0','5','A','2',$00,'5',$00,$03

    Thanks for looking.

    Steve

    Probably for ease of viewing, I'd just do it in the define_start section.
  • sijonessijones Posts: 16
    Hi Eric,

    Thanks for your reply.

    What I'm trying to find out is if there is a way of loading the data into the structure array when it is first declared?

    Something like:

    Button_Command _sButton_Command[] =
    {
    1 , $02,'3','0','0','5','A','2',$00,'1',$00,$03,
    2 , $02,'3','0','0','5','A','2',$00,'2',$00,$03,
    3 , $02,'3','0','0','5','A','2',$00,'3',$00,$03,
    4 , $02,'3','0','0','5','A','2',$00,'4',$00,$03,
    5 , $02,'3','0','0','5','A','2',$00,'5',$00,$03,
    }


    I've tried lots of ways of doing it but none of them compile.

    Kind regards,

    Steve
  • Joe HebertJoe Hebert Posts: 2,159
    sijones wrote: »
    What I'm trying to find out is if there is a way of loading the data into the structure array when it is first declared?
    Nope, no can do.
  • Joe HebertJoe Hebert Posts: 2,159
    sijones wrote: »
    An example of the data I want to load is:

    1 , $02,'3','0','0','5','A','2',$00,'1',$00,$03
    2 , $02,'3','0','0','5','A','2',$00,'2',$00,$03
    3 , $02,'3','0','0','5','A','2',$00,'3',$00,$03
    4 , $02,'3','0','0','5','A','2',$00,'4',$00,$03
    5 , $02,'3','0','0','5','A','2',$00,'5',$00,$03
    For that particular set of data you can do something like this:
    FOR (x=1; x<=5; x++) {
    
       _sButton_Command[x].Button_Number = x
       _sButton_Command[x].Button_Command = "$02,'3','0','0','5','A','2',$00,ITOA(x),$00,$03"
    }
    
  • ericmedleyericmedley Posts: 4,177
    I'm not a my computer with NS to try this but it might look something like...
    DEFINE_START
    
    _Button_Command.Button_Number[01]=1        _Button_Command.Button_Command[01]="$02,'3','0','0','5','A','2',$00,'1',$00,$03"
    _Button_Command.Button_Number[02]=2        _Button_Command.Button_Command[02]="02,'3','0','0','5','A','2',$00,'2',$00,$03"
    
    //ETC....
    
    
    
    

    but I think you need to make your integer declaration differently.

    STRUCTURE _Button_Command
    {
    INTEGER Button_Number[how ever many commands] // Button number
    CHAR Button_Command[how ever many commands][20] // RS232 Command
    }
  • a_riot42a_riot42 Posts: 1,624
    sijones wrote: »
    Hi,

    I've got the following structure defined:

    STRUCTURE _Button_Command
    {
    INTEGER Button_Number // Button number
    CHAR Button_Command[20] // RS232 Command
    }

    _Button_Command _sButton_Command[]


    Is there a shorthand method of loading fixed data into the structure array?

    An example of the data I want to load is:

    1 , $02,'3','0','0','5','A','2',$00,'1',$00,$03
    2 , $02,'3','0','0','5','A','2',$00,'2',$00,$03
    3 , $02,'3','0','0','5','A','2',$00,'3',$00,$03
    4 , $02,'3','0','0','5','A','2',$00,'4',$00,$03
    5 , $02,'3','0','0','5','A','2',$00,'5',$00,$03

    Thanks for looking.

    Steve

    If you want to copy data into an array of structures you will need a structure to copy it from.

    _Button_Command init


    init.Button_Number = 1
    init.Button_Command = "$02,'3','0','0','5','A','2',$00,'1',$00,$03"

    _sButton_Command[1] = init

    You might want to rethink your variable names though as its a little confusing. I don't see the point of the variables having the word button prepended since you already know its part of a button-command structure. IE:

    STRUCTURE _BtnCmd
    {
    INTEGER Btn
    CHAR Cmd[20]
    }
  • I usually just use an include file to load quasi-static info into structures like that. I personally find having a separate file with the config data in it to be the best way to store and read the data.
  • sijonessijones Posts: 16
    Many thanks for all the replies.

    Steve
Sign In or Register to comment.