Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Can’t Pass Negative Value to vbScript Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: March 10 2009 at 17:16 | IP Logged Quote GadgetGuy

I am attempting to capture home Freezer temps, using a 1-wire microLAN, and display them on my PH Home web page.

All works great EXCEPT that I am unable to pass the negative temps (the freezer air temps swing from -5 to +5 degrees) into my vbScript to compute an integrated value representing the actual food temperature.

Boiling it down to basics even the following simple vbScript will not execute with anything but positive numeric values. When the 'arg' is a negative value it fails!

Anyone know how to get around this?



__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 10 2009 at 18:39 | IP Logged Quote dhoward

Ken,

Im not sure how you're calling the vbscript function, but anytime you're dealing with negatives in PH, you should make sure you have a space character on either side of the - dash character. The PowerBuilder language that PowerHome was written in has a strange quirk about this.

Let me know if that helps,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: March 10 2009 at 21:20 | IP Logged Quote GadgetGuy

Dave -

The call is ...
Code:
ph_runscript_1(0,"C:\Program Files\powerhome\web\tempFreezerAve.vbs","main",number("[LOCAL5]"))


where LOCAL5 varies from -6.0 to +5.9

Thus I don't have the luxury of a "space."

The above posting error comment was obtained using the Multi-Edit window and the Run command with a parameter of -1 (which failed).

If I tried a variable of "- 1" with Run, that creates an error comment, so can't insert a space.


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 10 2009 at 22:44 | IP Logged Quote dhoward

Ken,

I took your exact ph_runscript_1 function and successfully ran it with the following command line:

Code:

ph_runscript_1(0,"C:\Program Files\powerhome\web\tempFreezerAve.vbs","main",ph_getvar_n(1 ,5))


The strange thing is that this only works if there ARENT spaces around the dash.

I'll have to look into this some more but it should get you by.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: March 11 2009 at 07:25 | IP Logged Quote GadgetGuy

Dave - I now know why your approach worked and mine didn't as there are two bugs I discovered.

First, I was testing with the Multi-Edit RUN command. I discovered that it will not pass a negative number as an argument, thus my simple example failed for me, that way, but not for you when you called it from a command line.

The second bug is that ph.setglobal_n will not write out a negative number that has been read by a preceeding ph.getglobal_n. The ph.getglobal read will show a negative number OK if displayed by a msgbox function, but if you read a negative and then write it back out, the written result is a "0". Thus the get/puts that moved the array elements towards the array end did not work but the ph.setglobal_n "FT01",CDbl(arg) just following the "Next" does work.

I tried using the CDBL function in the array moving functions but that didn't seem to help.

The ph.setglobal_s will write out a negative number.

After discovering I could use the global_s function to output negative numbers, I finally got around the issues, and have the Freezer logging working now by using an artful combination of string and number modes, thus...

Code:
Sub main(arg)
     Dim aveTemp, temp, offset, ndx1, ndx2
     offset=-1
     aveTemp=0
     for i=12 to 2 step -1
               'Build rolling data array of temps over 4 hours.
               'Temp sampled every 20 minutes; or 3 times per hour by PH.
               ndx1="FT" & RIGHT("00" & CSTR(i-1),2)
               ndx2="FT" & RIGHT("00" & CSTR(i),2)
               temp=ph.getglobal_s   (ndx1)
               ph.setglobal_s ndx2,Cstr(temp)
               aveTemp = aveTemp + CDBL(temp)
        Next
     ph.setglobal_n "FT01",CDbl(arg)
     aveTemp = offset + (arg + aveTemp)/12
     if not isnumeric(aveTemp)then aveTemp=0.0
     ph.setglobal_n "FT_FOOD", round(CDbl(aveTemp),1)
end Sub


BTW. With the "ndx1/ndx2 expressions I figured a way to write nice sequental numbered Vars into the Globals, where one normally gets T1, T10, T11, T2, T3, ... for an array from T1 ... T11. The ndx expressions force a zero into the single digit var names so I now get a nice T1, T2, T3, ... T9, T10, T11 sequence that is much easier to read information from.

I went to bed at midnight, last night with a big on my face!


Edited by GadgetGuy - March 11 2009 at 07:36


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 11 2009 at 22:16 | IP Logged Quote dhoward

Ken,

Well I spent a bit of time on this to find out exactly what the deal is with negative numbers.

First, you definately found a bug and the ph.setvar_n, ph.setvar_a, ph.setglobal_n, etc. type functions WILL NOT accept negative numbers. Huge bug on my part but Ive got it fixed for the next version.

Second, there are problems within PH with negative numbers on the ph_getvar_n, ph_getglobal_n, etc. type functions IF the data in the var has one or more spaces BETWEEN the negative sign and the number. This is a problem because Ive been telling people for years to always put a space before and after the negative sign. I have now corrected ALL of these functions so that they properly handle negative numbers no matter if there is no space or 1 or more spaces between the negative sign and the number.

Third, the NUMBER() function also has the same problem as the ph_getvar_n type functions where it will bomb if a space exists between the negative sign and the number. This is an internal function that I cant modify so I have created a new ph_number function that functions identical to NUMBER but does not care if there are spaces between the negative and the number.

Fourth, Ive discovered exactly what is the problem with negative signs within PowerHome that led me to always tell people to place a space on either side of the sign. PowerHome (PowerBuilder actually) MUST have a space BEFORE the negative sign IF the negative sign follows a COMMA. This is ONLY for literal negatives. A simple demonstation of this is the following formula:

if(1=1,-1,1)

The result should be -1 but it will result in an error. If you do:

if(1=1, -1,1)

(There is a space between the , and the -) then everything works as expected. You can also fix this by doing this:

if(1=1,(-1),1)

In the above example, computationally the same, but there is now no longer a negative sign immediately following a comma (it now follows an open parenthesis). If is not a problem with something like this:

if(1=1,ph_getvar_n(1,1),1)

even if LOCAL1 contains a negative number because the problem only exists with literals. The following is a problem though if LOCAL1 contains a negative number:

if(1=1,[LOCAL1],1)

because [LOCAL1] is a simple search and replace. If LOCAL1 contains a negative number with a space preceeding, it will work. It will also work if you place a space between the , and the [LOCAL1] or if you surround the [LOCAL1] with parenthesis.

Unfortunatley, this problem is not something that I can have any influence over. So, a minor amendment to what Ive been saying for years...instead of adding a space before and after the negative sign (this causes a problem with 2.1b of PowerHome and earlier but is fixed in future versions), just place a space before the negative sign and no space between the negative and the number. Alternatively, surround any negative number following a COMMA with parenthesis.

Sorry to be so lengthy but wanted to make sure I accurately explain the problem .

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: March 12 2009 at 07:52 | IP Logged Quote GadgetGuy

Good explaination Dave. On behalf of all of us, a great big thanks.

It sure had me going in circles for several days as the multi-edit Run and actual execution results when called from PH were different. So I was correcting things that didn't need it and not getting to things that did. Finally started testing by just Playing the macro (right click in macro in PH Explorer and select Play) and building it back up a line at a time.

Glad you found so much though. Makes it worth all of our mutual efforts.


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 

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