| Author | 
         | 
         
      
        
         
         bhlonewolf Senior Member 
          
 
  Joined: March 29 2007
 Online Status: Offline Posts: 198
          | 
        
         
          
           | Posted: May 04 2008 at 22:17 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
I don't know how it is that I've used PH for a solid year now w/o knowing this ...
 
 I decided it would make sense to consolidate logic into my own Formulas so I'm not duplicating some logic in various macros.  The thing is, how can I use my own formulas (that I've added to the formulas section) in macros?  Every time I try using them they have errors.
 
 Thanks,
 Brian
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         bhlonewolf Senior Member 
          
 
  Joined: March 29 2007
 Online Status: Offline Posts: 198
          | 
        
         
          
           | Posted: May 05 2008 at 13:23 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
OK, I think I kind-of figured out part of this.
 
 I used the ph_formulabtn to run a formula.  But what I'm really hoping to do is have that formula return a value.  For example, I have a formula called IS_SUN_UP (yeah, simple) that is just:
 
 if ( ph_seconds(now()) > [SUNRISE] AND
          ph_seconds(n ow()) < [SUNSET] , 1, 0)
 
 So running the formula should give me a 1 or 0 / true or false type of thing.  
 
 I can't seem to get the output of this formula in a macro. I have a few more complex ideas for formulas but figured I'd start here.  I know I can get the output of a macro, but logically speaking, seems like formulas are more correct for this kind of thing... thoughts?
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         TonyNo Moderator Group 
          
  
  Joined: December 05 2001 Location: United States
 Online Status: Offline Posts: 2889
          | 
        
         
          
           | Posted: May 05 2008 at 17:54 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
I think what you want is to be able to create your own formulas, but I'm not sure it's possible.
 
 What may get you close is a Submacro. Create your formula in a macro and then call it from other places with the Submacro command.
         | 
       
       
        | Back to Top | 
         
          
          
         | 
       
       
       
        |   | 
      
        
         
         BeachBum Super User 
          
  
  Joined: April 11 2007 Location: United States
 Online Status: Offline Posts: 1880
          | 
        
         
          
           | Posted: May 05 2008 at 19:22 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
The only thought I had was to stick the results in a variable then test that variable. Kind of a double whammy. 
  __________________ Pete - X10 Oldie
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         bhlonewolf Senior Member 
          
 
  Joined: March 29 2007
 Online Status: Offline Posts: 198
          | 
        
         
          
           | Posted: May 05 2008 at 21:26 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
hmmm... can't create formulas?  I thought that was the point of the formulas under formula explorer.  (?)
 
 I thought of a submacro too, but the functionality isn't a macro, it's a formula :)  I know I'm splitting hairs but when I think Macro, I think "execute a series of commands" and when I think Formula, I think, "evaluate some conditions and return a result" ...
 
 So the ultimate idea for me was to separate conditions into formulas, and then the macros would have just the basic execution steps...
 
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         BeachBum Super User 
          
  
  Joined: April 11 2007 Location: United States
 Online Status: Offline Posts: 1880
          | 
        
         
          
           | Posted: May 05 2008 at 21:46 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
So if I understand this correctly you want to, within a macro, call a formula with conditions and have the results passed back to the macro.
  __________________ Pete - X10 Oldie
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         bhlonewolf Senior Member 
          
 
  Joined: March 29 2007
 Online Status: Offline Posts: 198
          | 
        
         
          
           | Posted: May 05 2008 at 22:17 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Yup that's right -- so consider the formula above called "IS_SUN_UP" -- from a Macro, I want to determine if the sun is up and do different things.  So I'd like something like:
 
 JUMP  if([IS_SUN_UP]=1, 1, 999)
 
 Obviously the Sun Up formula is pretty easy to just cut and paste but others may be a bit more complicated, so it would be great to get them into my own "custom" formulas.
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         BeachBum Super User 
          
  
  Joined: April 11 2007 Location: United States
 Online Status: Offline Posts: 1880
          | 
        
         
          
           | Posted: May 05 2008 at 22:34 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Hopefully Dave is listening… I’ll look into it tomorrow.
  __________________ Pete - X10 Oldie
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         TonyNo Moderator Group 
          
  
  Joined: December 05 2001 Location: United States
 Online Status: Offline Posts: 2889
          | 
        
         
          
           | Posted: May 05 2008 at 22:52 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
You want to create a function with formulas. That's what I thought the Formulas table was for, too.    
  Edited by TonyNo - May 05 2008 at 22:53
         | 
       
       
        | Back to Top | 
         
          
          
         | 
       
       
       
        |   | 
      
        
         
         bhlonewolf Senior Member 
          
 
  Joined: March 29 2007
 Online Status: Offline Posts: 198
          | 
        
         
          
           | Posted: May 05 2008 at 23:00 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
AH ... so what do I do then?  :)
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         TonyNo Moderator Group 
          
  
  Joined: December 05 2001 Location: United States
 Online Status: Offline Posts: 2889
          | 
        
         
          
           | Posted: May 06 2008 at 07:45 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
We wait for Dave's wisdom!    
         | 
       
       
        | Back to Top | 
         
          
          
         | 
       
       
       
        |   | 
      
        
         
         BeachBum Super User 
          
  
  Joined: April 11 2007 Location: United States
 Online Status: Offline Posts: 1880
          | 
        
         
          
           | Posted: May 06 2008 at 08:52 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
In my testing the only way I can seem to pass parameters to and return codes back is using Variables. Maybe Dave has an easier way.
  __________________ Pete - X10 Oldie
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         bhlonewolf Senior Member 
          
 
  Joined: March 29 2007
 Online Status: Offline Posts: 198
          | 
        
         
          
           | Posted: May 06 2008 at 10:42 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Cool -- ok that makes sense.  Actually, in my case, I don't need to pass parameters into -- just get a return value.  Maybe if the value of a global variable could be a formula ... hmmm...
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         BeachBum Super User 
          
  
  Joined: April 11 2007 Location: United States
 Online Status: Offline Posts: 1880
          | 
        
         
          
           | Posted: May 06 2008 at 10:58 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Now that’s intriguing..   
  __________________ Pete - X10 Oldie
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         TonyNo Moderator Group 
          
  
  Joined: December 05 2001 Location: United States
 Online Status: Offline Posts: 2889
          | 
        
         
          
           | Posted: May 06 2008 at 13:23 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Sure! You could use ph_formula to evaluate it!
         | 
       
       
        | Back to Top | 
         
          
          
         | 
       
       
       
        |   | 
      
        
         
         bhlonewolf Senior Member 
          
 
  Joined: March 29 2007
 Online Status: Offline Posts: 198
          | 
        
         
          
           | Posted: May 06 2008 at 15:31 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Tony -- back up a sec -- could you explain that a bit?  'Cause everything I've tried so far hasn't worked.  Thx!
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         BeachBum Super User 
          
  
  Joined: April 11 2007 Location: United States
 Online Status: Offline Posts: 1880
          | 
        
         
          
           | Posted: May 06 2008 at 15:50 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
 Me too.. I need an example cause I can’t make the thing work.    
  __________________ Pete - X10 Oldie
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         dhoward Admin Group 
          
  
  Joined: June 29 2001 Location: United States
 Online Status: Offline Posts: 4447
          | 
        
         
          
           | Posted: May 06 2008 at 16:34 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Dohhhh!!! I knew I was forgetting something when I created the formulas table.  Pete is exactly right.  I need to have a formula function that returns the result of the formula.
 
 The next alpha will have  ph_formulabtn_s,ph_formulabtn_n,ph_formulabtn_d,ph_formulabt n_dt, and ph_formulabtn_t.  These functions work just like the ph_formulabtn except that it will return the result of the formula (it also does not do any sendkeys whether checked or not).
 
 I don't know how I missed this for so long (it was always the intent).
 
 I think what Tony was alluding to was to place the formula in a global variable in the GV table.  Then you could just use it directly use it in a macro with variable substitution.
 
 HTH,
 
 Dave.
 
         | 
       
       
        | Back to Top | 
         
          
          
         | 
       
       
       
        |   | 
      
        
         
         bhlonewolf Senior Member 
          
 
  Joined: March 29 2007
 Online Status: Offline Posts: 198
          | 
        
         
          
           | Posted: May 06 2008 at 19:32 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Thanks Dave!  Sounds good.  Now I'll have to upgrade when the next alpha comes out :)
 
 
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         TonyNo Moderator Group 
          
  
  Joined: December 05 2001 Location: United States
 Online Status: Offline Posts: 2889
          | 
        
         
          
           | Posted: May 06 2008 at 19:55 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
This is what I was thinking...
 
 
Code: 
   
    
    
      
       Set Global IS_SUN_UP if( ph_seconds(now()) > [SUNRISE] AND ph_seconds(now()) < [SUNSET] , 1, 0)
 ...
 JUMP if( ph_formula( "{IS_SUN_UP}")=1, 1, 999) | 
       
       | 
    
    | 
 
 
 
         | 
       
       
        | Back to Top | 
         
          
          
         | 
       
       
       
        |   |