Define_constant - Char
jjames
Posts: 2,908
How can this compile and still send the correct text to the panel? If you throw this into Studio, you'll see that it does contains a keyword (On Broadway) and a logical operation (Nashville!). And with Hank's Place, there's a single quote, making a good portion a string literal.
I'm using the "'!T',100,'TEXT'" command to send text to the panel. It all works (so I'm not complaining), but how does it work?
If I make Hank's Place like this:
I'm probably overlooking something really stupid. My problem is, if I were to move Hank's (or Frank's) place to the last value, it will make the rest of my code (including BUTTON_EVENTS, DATA_EVENTS, etc) appear as a STRING by the editor's preference. The funny thing is, my code still works. Is this a Studio bug?
I'm using the "'!T',100,'TEXT'" command to send text to the panel. It all works (so I'm not complaining), but how does it work?
If I make Hank's Place like this:
,"'Hank',39,'s Place'"It will display exactly that on the panel: 'Hank',39,'s Place'
I'm probably overlooking something really stupid. My problem is, if I were to move Hank's (or Frank's) place to the last value, it will make the rest of my code (including BUTTON_EVENTS, DATA_EVENTS, etc) appear as a STRING by the editor's preference. The funny thing is, my code still works. Is this a Studio bug?
DEFINE_CONSTANT CHAR CHAN_NAME[67][30]= { "The 40s" ,"The 50s" ,"The 60s" ,"The 70s" ,"The 80s" ,"The 90s" ,"America" ,"Nashville!" ,"X Country" ,"Hank's Place" ,"Bluegrass Junction" ,"Highway 16" ,"Top 20 on 20" ,"KISS" ,"MIX" ,"The Heart" ,"Sunny" ,"The Blend" ,"Cinemagic" ,"The Fish" ,"Spirit" ,"Deep Tracks" ,"XM Cafe" ,"Top Tracks" ,"Ethel" ,"Squizz" ,"The Loft" ,"Lucy" ,"Soul Street" ,"The Flow" ,"Suite 62" ,"The Rhyme" ,"RAW" ,"The City" ,"Special X" ,"Real Jazz" ,"Watercolors" ,"Beyond Jazz" ,"Frank's Place" ,"Bluesville" ,"Audio Vision" ,"The Move" ,"BPM" ,"The System" ,"Chrome" ,"World Zone" ,"The Joint" ,"XM Classics" ,"VOX" ,"XM Pops" ,"The Village" ,"On Broadway" ,"U-Pop" ,"Eye" ,"Enlighten" ,"Boneyard" ,"XMU" ,"XM Music Lab" ,"Fred" ,"The Groove" ,"Fine Tuning" ,"Radio Disney" ,"XM Kids" ,"Alegria" ,"Caliente" ,"MLB Home Plate" ,"High Voltage" }
0
Comments
"'!T',100,'Hank',39,'s Place'"
Change the double quotes to single quotes and add a double quote to the end of the each string.
Jeff
SEND_COMMAND "'!T',100,CHAN_NAME[X]"
right? I see what you mean about the ' in Hank's place causing the rest of the code to look like a string. I'm surprised it works with the why Studio is so picky about how you define and create strings. My guess is that the command must assume everything after the address is a string.
Pat
I'm guessing it's somewhat of a bug in Studio. I very well could be wrong though. The strange thing is, if I were to move Hank's Place to the bottom of the array, it would make the rest of my code to appear as a string, so all of my BUTTON_EVENTs, DATA_EVENTs . . . look like a string in code. And it still works and compiles fine! That's what's even more strange.
To do what you want to do, I think you need to do something like:
The above gives me an array of strings (that I can examine in debug) the first four of which are what would be expected by looking at the code.
Thanks for the suggestion . . . I just can't swallow typing in all of that, even though it would solve the "problem" of the formatting of the rest of the code. Since it's a module, I'll probably be the only one seeing the source code, so I guess it's not that big of a deal. Though I will keep the suggestion in mind.
I just thought it was quite strange what I was seeing, and hoping others could verify.
CHAR sString[] = "Testing"
I would not expect this to work. In fact, If I make that declaration in define_variable or try to make such an assignment in define_start, it does not work. But, in define_constant, the above seems to have the exact same result as what I would consider appropriate:
CHAR sString[] = 'Testing'
So, I think we are seeing a feature of the define_constant section of which I, certainly, was not aware. In define_constant, it appears that you can create string literals by enclosing strings in double quotes with all the characters within the double quotes being represented exactly in the resulting string. A single quote or comma within the double quotes appears in the resulting string as a single quote or a comma. Reserved words are interpreted as ASCII characters and not as reserved words. BUT, typical string expression syntax does not give the expected result.
Great work. Now here's the $64k question . . . is this a good thing or a bad thing? I can see it being good as long as it didn't mess with the appearance of the following code. If AMX could fix this visual problem, I'd be happy with it. Otherwise, it's a pain to to code with the editory all messed up.
Personally, I wouldn't put it in DEFINE_CONSTANT either. I'd declare it as a CONSTANT CHAR[] in DEFINE_VARIABLE. I'm not certain the above will work in DEFINE_CONSTANT (and I can't really test it right now, I'm at a customer's just waiting on a SAT receiver guide download ... ).
CHAN_NAME[10] is a length 3 string " H's "
the compiler warns that a string is being cast to a character.
To do this in the DEFINE_VARIABLE section, I think you have to specify each character individually like:
{'H','a','n','k',39,'s',' ','P','l','a','c','e'},
I was surprised to see that the way Jerimiah wrote the code worked. It appears to me that everywhere but in DEFINE_CONSTANT, syntax like:
sDummy = "string"
gives a compiler error. Either this is an intentional feature of which I was not aware or an unintentional feature. If it's the latter, I'd be wary of depending on the presence of the feature in the future.
if you add a comment to those lines which contain an odd number of single quotes, you can limit the editor to hosing just those lines.
for example:
,"Hank's Place" //'
is less than beautiful, but it's not gross and disgusting.
If you want to use a single quote within a literal string you can escape the quote by adding another quote, in other words double single quote it. For example,
instead of:
cTest = ??Hank?,39,?s Place??
or
cTest = ??Hank?,$27,?s Place??
you can simply use:
cTest = ?Hank''s Place? //(that's 2 single quotes ' and ' between k and s)
Drifting off topic:
Jeremiah ? Do you have another double dimensioned array with the channel numbers? You asked in different thread when to use structures vs. arrays. This might be a good example of when to consider using a structure. If I need more than one dimension to describe something, I normally go right to a structure (unless I need to pass the data into a module in which case I?m stuck with multi dimensional arrays.)
In my opinion structures are easier to read, organize, and modify. But that?s just me. I?m not saying multidimensional arrays are wrong, I just prefer structures and use them extensively.
If I wanted to organize XM station data, I would probably do something like this:
I know this doesn?t answer the original question you posted. I just wanted to offer an alternative point of view. Not right, not wrong, just my take on it.
Regarding the CHAR array, I don?t know what Netlinx is doing but it sure seems wrong and doesn?t sit well in my stomach even though it ?works?. I?m with Harold and would be wary of using it in case it?s ?fixed? later.
Joe:
I set everything up as an array and didn't use a structure in this. The module I used this in was originally using a structure, and will admit it was easy to read. The problem was that it was written poorly, so I took it upon myself to rewrite it, and decided to use arrays. The reason why I like to learn towards using arrays rather than structures is . . . well, I just do not know enough about them, or how to use them. They do seem powerful enough to get quite a bit done, but I just haven't gotten around to looking into them, hence the other thread.
Aside from that, since this module won't be used widespread across the country I guess I can deal with what I'm observing.
I'm suprised that this will compile. I would have thought that the compiler would think it's two seperate string literals that weren't glued by the comma, and double quotes and spit up a top secret error that gives no explaination of what's wrong.
Geez . . . I still have a lot to learn.