Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Button label problems with charAt(x)
This thread has 6 replies. Displaying all posts.
Post 1 made on Monday February 9, 2009 at 00:27
alpha
Long Time Member
Joined:
Posts:
September 2003
258
I have been working on an activity that changes the label on a button when you rotate the dial.When you press the button, it reads the label and executes actions on other buttons in sequential order with the charAt command. If the Label is 259 it executes the 2 button action, the 5 button action , and the 9 button action. That part works but, if the Label is a single digit it will add a 0 button action twice( 7 will come out as 700). When the Label is a double digit it sends a 0 button action( 25 will come out as 250). These extra Zeros have me stumped .

I plan to start over and rewrite the script. I would like to add the ability to Skip groups of numbers and possibly rework it as a Radio Dial Tuner also( I currently use it as a TV Channel Changer).

I am looking for some direction writing ths script. I was never trained in JavaScript so my approach is one from the Prontoscript Developers Guide.I have some books but they deal mostly with Internet aspects of Javascript . It took me three days to find charAt ( ) command and figure out how to incorporate into this activity.

I hope to eventually get something working and post it in the file area.

Thanks,
Alpha.
Project Boredom 2 is here. [Link: mediafire.com]
------------------------
Check Version 1 & 2 out in the files section.
Post 2 made on Monday February 9, 2009 at 03:52
buzz
Super Member
Joined:
Posts:
May 2003
4,376
alpha,

You may have a simple spelling error. I assume that you somehow test the length of the string that you are extracting digits from. Your routine seems to always process three digits. Perhaps you are processing "MYstring", but checking the length of "MyString". Another subtle error is using "=" rather than "==" in a comparison.
Post 3 made on Monday February 9, 2009 at 17:39
GuerillaBuild
Long Time Member
Joined:
Posts:
December 2008
79
If you're looking for absolute control over a variable length string, I suggest that you also look at using regular expressions (supported under pronto/javascript). Although they can be mind bending to construct, if done correctly they always work!

With Regex you really don't have to worry about string length as you are telling it (most of the time) to look for a pattern (ex: find all numbers inside the string). You can also use Regex to slice, dice and melange the result to your hearts content. If you're interested there is a Regex GUI builder program called Espresso or Expresso that can help you write Regex expressions.
You can hide almost anything until you have to put the drywall up!
Post 4 made on Monday February 9, 2009 at 17:57
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,997
There's a rather simple chapter in RegEx in Flanagan. There's also another thread that I posted over 1 year ago that has a regular expression tutorial link.

And, recently, I posted a simple RegExp to extract hour, minute, and ampm from GUI.getDisplayString();
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 5 made on Thursday February 12, 2009 at 22:59
alpha
Long Time Member
Joined:
Posts:
September 2003
258
Thank you for the rapid responses. I had no idea about Regular Expressions. The first book looked at was the JavaScript Cookbook printed in 1997. It did not cover Regular Expressions at all (the book cost me half a buck). I am waiting to get Flanagans from my library.

GuerillaBuild was right . Just looking at a expression is mind bending at first. So I might try something like this to start.

re = /^(\d)(\d)(\d)$/

I am not sure about the rest. Maybe something with $1 ,$2, $3 somewhere somehow to separate the digits.

Thanks again.
Project Boredom 2 is here. [Link: mediafire.com]
------------------------
Check Version 1 & 2 out in the files section.
Post 6 made on Friday February 13, 2009 at 11:29
GuerillaBuild
Long Time Member
Joined:
Posts:
December 2008
79
Hi Alpha,
if you're looking for some free info on the web regarding regex, try W3Schools. They have reference material on everything java and even allow you to test out examples.
You can hide almost anything until you have to put the drywall up!
Post 7 made on Friday February 13, 2009 at 14:17
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,997
See this post for example of using RegExp.$1, RegExp.$2, RegExp.$3 based on pattern that was used to match the string.

[Link: remotecentral.com]
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature 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.

Hosting Services by ipHouse