Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Simple macro question - Message Box Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
jwshome
Newbie
Newbie


Joined: July 02 2006
Online Status: Offline
Posts: 17
Posted: December 31 2006 at 10:25 | IP Logged Quote jwshome

I feel like I'm asking all the stupid questions on this site.

I have a simple macro to get the current temperature from a Yahoo web page. I am able to use ph_regexdiff to get the temperature value (as an integer) into the variable [GLOBAL2]. I then transfer this value into a global variable called CURTEMP. This seems to work fine - when I use Powerhome Explorer to check the value of CURTEMP the changes from the macro are accurately reflected.

Finally, I want to pop up the value in a message box. If I pop up [GLOBAL2], or "[GLOBAL2]", it shows the correct result; but if I pop up CURTEMP it evaluates to !.

I assume this has something to do with strings and numbers, but I've tried many iterations (using the number and string functions; using quotes, etc.) and can't quite figure it out.

Can someone explain the error I'm making? Thanks.
Back to Top View jwshome's Profile Search for other posts by jwshome
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 31 2006 at 11:31 | IP Logged Quote TonyNo

CURTEMP is a Global Variable which needs to be surrounded with braces: "{CURTEMP}".

System variables use brackets, as you have found.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 31 2006 at 11:58 | IP Logged Quote dhoward

No questions are stupid .

It could be some confusion concerning PowerHome's variables. Over time, the variables have evolved but some of the older naming has stuck.

PowerHome has the concept of two types of variables. System variables and Global variables. System variables are only stored within memory. Restart PowerHome and your system variables are wiped out. Global variables are user defined variables and are stored within the database. Whatever value you set for a global variable will remain throughout restarts and whatnot until you change the value.

The number and types of system variables are fixed (some system variables can be influenced by your database definition such as X10 devices however). Most of the system variables are specialized, holding a specific value for a specific purpose, but there are 3 sets of general purpose system variables called LOCAL, TEMP, and GLOBAL. They used to have 3 distinct purposes, but over time, this has blurred somewhat.

There are 10 LOCAL variables (LOCAL1 through LOCAL10), 10 TEMP variables (TEMP1 through TEMP10) and 20 GLOBAL variables (GLOBAL1 through GLOBAL20). The GLOBAL variables are just that, GLOBAL. They are visible from within any macro or formula and their values do not change unless changed (or a restart). These variables are completely different from the database global variables.

The differences between LOCAL and TEMP system variables is now a little blurred. Originally, LOCAL variables were a fresh copy with every execution queue process. Launch a macro, it got a fresh copy of LOCAL variables. If that macro called another macro, the second set of LOCAL variables would be blank and separate from the first macros LOCAL variables. The TEMP variables were similar to LOCAL variables except that the first macro would pass copies of it's TEMP variables to the second macros TEMP variables. This was only a 1 way copy. Changes made to the TEMP variables in the second macro would NOT flow back up to the first macro when the second macro exited and control returned to the first macro. This distinction has laxed in certain areas and alot of the time the LOCAL variables are available and passed down to sub programs and such. However, to guarantee expected operation, you should think of the LOCAL variables as being fresh with each new macro or posted formula.

Global variables (not the GLOBAL system variables) are completely user defined and always available in every scope of the program. Since they are stored within the database, there are length constraints on global variables. The maximum length for a global variable is 1024 characters. Since system variables are stored within memory, they are unlimited in their storage capabilities (there are practical constraints of course).

That should explain the two different variable concepts within PowerHome. With that said, they are referenced within code two different ways, which I suspect is your problem (took me awhile to get there didnt it). System variables are enclosed within brackets like so: [LOCAL1], [TEMP5], or [GLOBAL7]. Global variables are enclosed within curly braces such as {CURTEMP}. To display your variable, you probably just need to use "{CURTEMP}".

Hope this helps,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
jwshome
Newbie
Newbie


Joined: July 02 2006
Online Status: Offline
Posts: 17
Posted: December 31 2006 at 14:30 | IP Logged Quote jwshome

excellent, thanks (for both explanations...)
Back to Top View jwshome's Profile Search for other posts by jwshome
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum