Home AMX User Forum AMX General Discussion

Constant Array Question

Hi All,

I love using Constant Array it save me time in code logic but i have a question for you folk.

I'm using integer constant array this way
TP_SRC1		= 21
TP_SRC2		= 22
TP_SRC3		= 23
TP_SRC4		= 24
TP_SRC5		= 25
TP_SRC6		= 26

integer TP_SRC_LIST[]={ 
TP_SRC1,TP_SRC2,TP_SRC3,TP_SRC4,TP_SRC5,TP_SRC6}

work perfectly has i know,

but i want to do the same thing with string constant
char cExtronUSB1[2] = {'1^'}
char cExtronUSB2[2] = {'2^'}
char cExtronUSB3[2] = {'3^'}
char cExtronUSB4[2] = {'4^'}
char cExtronUSB0[2] = {'0^'}

char cExtronUSB_List[][2]={ // String to send
cExtronUSB1,
cExtronUSB0,
cExtronUSB0,
cExtronUSB2,
cExtronUSB3,
cExtronUSB0}

It is possible? Right now if i'm using Debug to see my array, it's empty

I need to do my array this way, to be able to see it in Debugger.
char cExtronUSB_List[][2]={ // String to send
{'1^'},
{'0^'},
{'0^'},
{'2^'},
{'3^'},
{'0^'}}

Thanks all for your help.

Comments

  • a_riot42a_riot42 Posts: 1,624
    Raphayo wrote: »
    Hi All,

    I love using Constant Array it save me time in code logic but i have a question for you folk.

    I'm using integer constant array this way
    TP_SRC1		= 21
    TP_SRC2		= 22
    TP_SRC3		= 23
    TP_SRC4		= 24
    TP_SRC5		= 25
    TP_SRC6		= 26
    
    integer TP_SRC_LIST[]={ 
    TP_SRC1,TP_SRC2,TP_SRC3,TP_SRC4,TP_SRC5,TP_SRC6}
    

    work perfectly has i know,

    but i want to do the same thing with string constant
    char cExtronUSB1[2] = {'1^'}
    char cExtronUSB2[2] = {'2^'}
    char cExtronUSB3[2] = {'3^'}
    char cExtronUSB4[2] = {'4^'}
    char cExtronUSB0[2] = {'0^'}
    
    char cExtronUSB_List[][2]={ // String to send
    cExtronUSB1,
    cExtronUSB0,
    cExtronUSB0,
    cExtronUSB2,
    cExtronUSB3,
    cExtronUSB0}
    

    It is possible? Right now if i'm using Debug to see my array, it's empty

    I need to do my array this way, to be able to see it in Debugger.
    char cExtronUSB_List[][2]={ // String to send
    {'1^'},
    {'0^'},
    {'0^'},
    {'2^'},
    {'3^'},
    {'0^'}}
    

    Thanks all for your help.

    Where are you doing your assignment? I do them in define_start. You also have to make sure that length_array returns what you think it should return. If length_array returns 0 you will have to use set_length_array.

    I don't assign commands into arrays this way.
    char cExtronUSB1[2] = {'1^'}
    char cExtronUSB2[2] = {'2^'}
    char cExtronUSB3[2] = {'3^'}
    char cExtronUSB4[2] = {'4^'}
    char cExtronUSB0[2] = {'0^'}
    

    I do it this way instead:
    define_constant 
    cnExtronUSB1 = 1
    cnExtronUSB2 = 2
    cnExtronUSB3 = 3
    cnExtronUSB4 = 4
    cnExtronUSB5 = 5
    
    define_variable
    char sExtronCmds[][8]
    
    define_start
    sExtronCmds[cnExtronUSB1] = {'1^'}
    sExtronCmds[cnExtronUSB2] = {'2^'}
    sExtronCmds[cnExtronUSB3] = {'3^'}
    sExtronCmds[cnExtronUSB4] = {'4^'}
    sExtronCmds[cnExtronUSB5] = {'5^'}
    
    


    Paul
  • RaphayoRaphayo Posts: 111
    i set my array in define_constant or define_variable if I want to be able to modify it during process.
  • GregGGregG Posts: 251
    Unfortunately NetLinx doesn't let you do that for a string definition, but you can end up with a similar effect using constants to refer to the initial extron commands in their own array, like this:
    DEFINE_CONSTANT
    // Strings for each USB select:
    char cExtronUSB_Cmd[][2]={
      {'1^'},
      {'2^'},
      {'3^'},
      {'4^'},
      {'0^'}
    }
    // Constants to refer to the above commands
    EXTRON_USB_1	=	1
    EXTRON_USB_2	=	2
    EXTRON_USB_3	=	3
    EXTRON_USB_4	=	4
    EXTRON_USB_0	=	5
    
    // USB to use for each item (source?)
    integer nExtronUSB_List[]={
    	EXTRON_USB_1,	// 
    	EXTRON_USB_0,	// 
    	EXTRON_USB_0,	// 
    	EXTRON_USB_2,	// 
    	EXTRON_USB_3,	// 
    	EXTRON_USB_0	// 
    }
    
    DEFINE_EVENT
    Button_Event[dvTP,nSelectPCButtons]
    {
    	Push: Send_String dvExtron,"cExtronUSB_Cmd[nExtronUSB_List[Get_Last(nSelectPCButtons)]]"
    }
    
Sign In or Register to comment.