Home AMX User Forum NetLinx Studio

Sending a Constant in a String

DEFINE_CONSTANT
CHAR cnPowerSet[]= "$A0,$60"

SEND_STRING dvDevice,"cnPowerSet,$0A,$0D"

How come the , in the constant is being sent? I've used similar methods before and never had the , in the output.

Thanks.

Comments

  • HedbergHedberg Posts: 671
    Don't use double quote string expressions in define_constant -- it doesn't work as you would hope.

    Try something like:

    char cnPowerSet = {$A0,$60}
  • TurnipTruckTurnipTruck Posts: 1,485
    Hedberg wrote:

    Try something like:

    char cnPowerSet = {$A0,$60}

    Tried that too. Same result.
  • Try to use it with a variable:
    Some like that:

    define_variable
    CHAR astrPowerSet[]= {$A0,$60}

    SEND_STRING dvDevice,"astrPowerSet,$0A,$0D"
  • HedbergHedberg Posts: 671
    I made an error in my prior post.

    this is what it should have been:

    define_constant

    char cnPowerSet[] = {$A0,$60}


    That results in an array with two elements and appears as expected in debug.

    This:

    define_constant

    char cnPowerSet[] = "$A0,$60"

    results in an array with seven elements and appears to be identical to this:

    char cnPowerSet[] = '$A0,$60'

    It appears that trying to use double quotes to define a string expression in define_constant should cause a rhs error and not compile -- instead Netlinx misinterprets the syntax and gives an unintended result.
  • yuriyuri Posts: 861
    define as a variable, then fill the variable in define_start?
  • avi_daveavi_dave Posts: 62
    just do this

    Code:
    DEFINE_CONSTANT
    CHAR cnPowerSet[4] //four elements

    DEFINE START

    cnPowerSet = "$A0,$60,$0A,$0D" //fill array
  • DHawthorneDHawthorne Posts: 4,584
    avi_dave wrote: »
    just do this

    Code:
    DEFINE_CONSTANT
    CHAR cnPowerSet[4] //four elements

    DEFINE START

    cnPowerSet = "$A0,$60,$0A,$0D" //fill array

    I'm not so sure that will give you the desired results - you are declaring a constant, then changing it's value in startup. So it's either not going to work, or it's not really a constant.

    It's also unnecessarily cumbersome, in my opinion, when CHAR cnPowerSet[] = {$A0,$60,$A0,$0D} gives an identical result, and is on a single line, where you can see all you need without jumping around.
  • avi_daveavi_dave Posts: 62
    point taken, other side of the coin when doing string queing, I can change the element value lets say I need to do checksums, I know it needs 4 elements for power lets say, so for that I just declare a variable type array and fill it as I go along
Sign In or Register to comment.