Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Handling a Null Variable 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: June 29 2013 at 12:21 | IP Logged Quote GadgetGuy

I'm using the ph_regexsnap PH function to parse the Wind
Speed data off a weather site to use in my home
environmental CC report.

Unfortunately occasionally the web site omits the Wind
Speed and then regxsnap returns a null string to
[LOCAL3].

This always causes fatal syntax errors in subsequent
calculation formulas.

I have not been able to discover a method to detect and
correct this issue, however, as "IsNull" and "IsNumber"
testing on [LOCAL3} tests also fails with a syntax error.

Is there a method to detect this empty [LOCAL3] so I can
populate it with the last good data before doing follow-
on calculations?   

__________________
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
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: July 01 2013 at 19:26 | IP Logged Quote TonyNo

Did you try to compare it to ""?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: July 02 2013 at 06:02 | IP Logged Quote GadgetGuy

Yes.

Sorry, I forgot to put that in my post. Comparing to ""
was actually the first thing I tried.

I'm really stumped by this one, as I've never encountered
this kind of quirk.

I wonder if ph_regexsnap just throws off some wierd value
when it doesn't get a match that then puts a wrench in
follow-on code?   

__________________
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
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: July 02 2013 at 08:25 | IP Logged Quote grif091

What about assigning [LOCAL3] equal to " " before calling the web site that does not return Wind Speed. If [LOCAL3] is not being set because Wind Speed is missing perhaps pre-assigning some value would at least make the variable accessible. Just a SWAG.

__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: July 02 2013 at 16:20 | IP Logged Quote GadgetGuy

Hum Lee -

Interesting suggestion. I'll give it a try and we'll see
what happens.

Will report back (but it sometimes is many weeks between
errors).

__________________
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
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: July 06 2013 at 19:48 | IP Logged Quote GadgetGuy

Didn't work. I still have gotten errors.

This doesn't seem right. There must be a way to test for
valid data, or not, to prevent Syntax errors.

Dave - what am I overlooking?


__________________
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
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: July 22 2013 at 19:47 | IP Logged Quote gg102

Have you tried LEN ?
Back to Top View gg102's Profile Search for other posts by gg102
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: July 23 2013 at 15:22 | IP Logged Quote GadgetGuy

Thanks gg102 for your suggestion. Yes, in fact LEN was
the only way I could make it work and then Dave advised
the following, which TOTALLY solved the problem.

Quote:
-- Dave Howard --

The main problem you're having with null values is their
limitations with variable substitution. You should ONLY
use variable substitution when you KNOW the value in the
variable is what you expect. If you're unsure of the
data in variable, you should use the ph_getvar_?
functions to retrieve the variable with the datatype your
formula requires. So instead of:

ph_msgbox("","[LOCAL3]",0)

you would use:

ph_msgbox("",ph_getvar_s(1,3),0)

This would return the value in [LOCAL3] as a string no
matter what the data it contains (including null). You
should then be able to compare it to an empty string
(""). If you prefer to use variable substitution, you
can use something like this to force a proper value into
the variable after retrieving unknown data:

ph_setvar_s(1,3,ph_getvar_s(1,3))


As always, Dave "nailed it"



__________________
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