Posted: June 10 2004 at 15:51 | IP Logged
|
|
|
Dean,
The "Send Email" macro command uses MAPI which will open your Outlook Express and could cause a hang. You'll want to use the ph_sendsmtpemail formula function instead to eliminate any chance of hanging.
The "Process Email" macro command also can hang. The ph_processemailthread function uses the same technique to process incoming email but is instead launched in a separate "thread" or process different from PowerHome. It can still hang, but the separate process will be hung and PowerHome can continue working.
Macro commands are the actions that each macro detail line can perform. It is the third column from the left and is labeled "Type". These commands only exist within macros, however, almost every macro command is duplicated with a formula function. Some that are not duplicated are the "Message Box", "Goto Label", "Jump", etc because these only make sense within the context of a macro.
Formulas are nothing more than a logical mathematical relationship. 1 + 2 is a formula. We are simply adding two numbers together. "This is " + "a string" is also a formula. Here Im adding two strings together which essentially concatenates them. It's not really mathematical, but in terms of computers and PowerHome, we can treat it the same way. Now in order for a formula to make sense, we entity within the formula must be the same type. You cant add a string to a number or similar. Now, there are functions that will convert between string and number and vice/versa as well as the other entity types. This is illegal: "The result is " + 4. This is legal: "The result is " + string(4). The other valid entity types are date, time, and datetime.
Now that we understand a formula, we have a large number of functions that can be used within a formula. The PowerHome specific formulas all start with "ph_". A function will return a single value that is either string, numeric, date,time, or datetime. You can add, subtract, etc. functions pretty much just like you do numbers. If the result of a function returns a number, you can add that to a number. If you wanted to add a numeric function to a string, you could convert the output of the numeric function to a string and add it to a number.
A formula is evaluated from left to right in order of the rules of precedence. Multiplication and division are performed first followed by addition and subtraction. You can use parenthesis to force a particular order.
When PowerHome encounters a formula, it is evaluated. Once a formula is evaluated, it will produce a result. In some cases, this result may be important and can be used elsewhere. In other cases, the act of the formula evaluation (usually with functions involved) produces the desired result.
Say you wanted to send an X-10 command to turn a light at C5 on. You could do this with a couple of macro commands, a couple of formulas, or a single formula. If using formulas, you could evaluate first: ph_x10(1,"C",5,0). The result of this function will be 0. You could then next evaluate: ph_x10(1,"C",102,0) and the light at C5 will turn on. The result of this formula will also be 0. You could also add these two formulas together within a single formula: ph_x10(1,"C",5,0) + ph_x10(1,"C",102,0). This will have a result of 0 as well.
I hope that helps to understand formulas and the difference between them and macro commands a little better .
Functions are used only within formulas. Formulas that are usually specific to PowerHome for controlling things start with "ph_". Other functions that don't start with "ph_" are typically generic such as if(),string(),mid(),integer(),etc. Some of the "ph_" functions won't seem to be specific to PowerHome control but instead have a specialized purpose.
Where can formula's be used? Just about anywhere. They are used in a large number of macro commands (always in the "Send Keys / TTS / Dim / Formula" field). They can be used in triggers, timed events, voice recognition, etc. There is a macro command called "Formula" whose only purpose is to allow you to evaluate a formula. There is also a formula function called "ph_macro" which allows you to call a macro.
A "Send Keys" is a formula. This formula is evaluated and the result is sent as keystrokes to the current application with focus. This could be PowerHome or it could be another application that you switched to with either a macro command or the ph_switchto function. This Send Keys formula can be as simple as: "This is a string of characters which will be sent as keystrokes to the current application with focus". You can see that this is just a string, but it satisfies the rules of a formula. This formula will be "evaluated" which will just return the string itself as the result. This result is then sent as keystrokes to the app with focus.
There is also a formula function called "ph_sendkeys()". The string within the function will be sent as keystrokes to the current application.
You can use a formula to create a for-next type of statement. There is a formula function ph_forloop (as well as ph_whileloop and ph_doloop). It's handy to use when you need looping within a formula. But if you are trying to create looping within a macro, you're better off to use the "Jump" command or the "Label", "Goto Label" commands (yes, ol' Nicholas would be rolling ). In the "Send Keys / TTS / Dim / Formula" field of a "Jump" or "Goto Label" command, you can use a formula. It can be as simple as "- 6" to jump back six lines or more complicated such as: case([LOCAL1] when 1 then "SET TEMPERATURE" when 2 then "SET HUMIDITY" when 3 then "GET TIME" else "EXIT") in the case of a "Goto Label" command to conditionally jump to certain locations based upon the value of the [LOCAL1] system variable.
The help is a standard Windows Compiled HTML help file (at least for the functions which is all I have in there right now). If you go to the "Search" tab and type something such as "x10" it will search for anyplace within the text that the "x10" appears. From my testing, it can be a separate word or a part of a whole word, in effect automatically being a wildcard search. Let me know if Ive got this wrong.
And last, but not least (I think I hit upon all your questions ), you can see some samples by opening up the samples database (you may have already done this because I see you mention "documented examples"). If you havent already, you can open the sample database directly from the PowerHome Explorer by pressing the "F7" key (or pressing the appropriate toolbar button or navigating the menu Edit->Database) and selecting the sample database default located in c:\program files\powerhome\database\phsample.db. This is pretty much a duplicate of my own database and while the code is not documented, does show a lot of what can be done.
Sorry to be so lengthy, but I hope this helps.
Dave.
|