|
|
|
Philips Pronto Professional Forum - View Post
|
|
|
|
|
|
|
The following page was printed from RemoteCentral.com:
Topic: | System.setGlobal problem This thread has 4 replies. Displaying all posts. |
|
Post 1 made on Friday August 24, 2007 at 11:14 |
Damothesumo Lurking Member |
Joined: Posts: | September 2005 7 |
|
|
I am attempting to program the TSU9600 for a multi room installation. I would like to create a global variable for the selected room, for use in the volume control of an audio matrix system. I have tried declaring the global in the HOME properties -advanced tab as follows
var Room System.setGlobal(Room) = 0 // Reset to Room to 0 every time home page is visited I get errors when I try to set the global variable to other values, and when I try to reference this global.
I'm new to JAVA so would appreciate someone pointing out my errors.
|
|
Post 2 made on Friday August 24, 2007 at 12:07 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
System globals are named strings. As such the setGlobal function takes two arguments; the name for the string and the value of the string such as:
System.setGlobal("Room","0");
to retrieve the string use x=System.getGlobal("Room"); which will set x as a string containing a 0
x=System.getGlobal("Room")-0; will force the conversion of the string to a number and set x as the integer 0
Hope that helps. Java, being without type declarations does most things as you would expect. The + operator however is overloaded and means addition or concatenation so a="1"; a=a+1; results in a being the string "11", while a="1"; a=a-0+1 results in a being the integer 2. This one burns me all the time as I deal with many languages and really prefer them to be strongly typed.
|
|
OP | Post 3 made on Friday August 24, 2007 at 12:32 |
Damothesumo Lurking Member |
Joined: Posts: | September 2005 7 |
|
|
I just amended my code as you suggest, and it works!! Hurrah, I've been trying every combination possible, but would have never figured out how to convert the string to an integer. Many thanks for your swift and helpful reply.
|
|
Post 4 made on Friday August 24, 2007 at 14:27 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
The method I showed you is a "trick", but it always works.
Strings that are numeric can be "formally" converted to a number as stringname.toNumber e.g. a="123"; x=a.toNumber will result in x being a number. Java holds numbers internally in floating point but that rarely causes a problem unless you are extracting bits. I use "JAVA Script, The Definitive Guide" by Flannagan as my reference. Easy to read, well laid out and explains with examples.
|
|
Post 5 made on Friday August 24, 2007 at 21:07 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 12,999 |
|
|
Number('123'); will convert to a number or the special value NaN (Not A Number). Also note that Javascript support both Positive and Negative infinity values. (See W3 schools for more info).
1/0 --> Positive Infinity -1/0 --> Negative Infinity
Any text to numeric conversion that fails (Number() or parseInt())will return NaN and you can detect this with
isNaN(value)
var a=Number("123"); var b=parseInt('abc',10); var c=parseInt('10',16);
System.print(a) --> 123 System.print(b) --> NaN System.print(isNaN(b)) --> true System.print(c) --> 16 ie. 10 in base 16(hexadecimal) is base 10 value of 16.
There's also a parseFloat function.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
|
Before you can reply to a message... |
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now. |
Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.
|
|
|
|