Home AMX User Forum NetLinx Studio

String Literals

Anyone know if there is a difference in the following commands...

SEND_STRING someDevice, 'Hello World'

and

SEND_STRING someDevice, "'Hello World'"


Thanks

Comments

  • DHawthorneDHawthorne Posts: 4,584
    As stated, none. However, if you need to mix ASCII characters with variables, decimal or hex values, you need the quotes, as in:

    SEND_STRING someDevice, "'Hello ', StringVar, 13"

    My habit is to always use the double quotes in any case.
  • GSLogicGSLogic Posts: 562
    The first 'HelloWorld' is a literal -ASCII

    The second "HelloWorld'" is a pre-defined variable

    The first command will work if it is all you want to send but if you want to add a variable with it, then you must use the " ". It's good practice to ALWAYS use the " " in all command like:

    SEND_STRING someDevice, " 'Hello World' "

    with VARIABLE:
    SEND_STRING someDevice, " 'Hello World', someVAR"

    Hope this helps!
  • sonnysonny Posts: 208
    Thanks for the replies...

    I've seen documentation with the literal within single ticks by themselves, and with double quotes around the single ones. Didn't think there was a difference, just wasn't sure.
  • You will need to be a little carefull when dealing with variables in Netlinx as some may operate differently depending on the section of code you are in. Learned this the hard way. Here's a sample:

    DEFINE_CONSTANT
    CHAR EF_2280[] = 'F01'
    CHAR PGM_VOLUME_UP[] = "EF_2280,'MACROX4'"

    BUTTON_EVENT[dvTPANEL,51]
    {
    PUSH:
    {
    SEND STRING dvA_CONF,"PGM_VOLUME_UP"
    }
    }

    it ended up sending "EF_2280,'MACROX4'" out of the RS-232 port.

    Assigning CHAR PGM_VOLUME_UP[12] in the DEFINE_VARIABLE section instead, and then adding the statement PGM_VOLUME_UP = "EF_2280,'MACROX4'" in the DEFINE_START section fixed the issue and sent "F01MACROX4".
    Have not researched further why this is the case, but I have become very careful with strings in the DEFINE_CONSTANT section.
  • sonnysonny Posts: 208
    DEFINE_CONSTANT
    CHAR EF_2280[] = 'F01'
    CHAR PGM_VOLUME_UP[] = "EF_2280,'MACROX4'"

    just a guess, but the statement "EF_2280,'MACROX4'" is an executable statement that happens during runtime to dynamically build a string. Stuff that goes in the DEFINE_CONSTANT section gets resolved at compile time, and the compiler is treating this differently.
Sign In or Register to comment.