HP Forums
How to control if a list isn't void? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: How to control if a list isn't void? (/thread-4277.html)



How to control if a list isn't void? - salvomic - 07-01-2015 11:02 PM

hi,
I've this code:

Code:

IF (SIZE(Long_Lat)==2) THEN long:= Long_Lat(1); lat:= Long_Lat(2);
  ELSE long:= →HMS(-14°30′40″); lat:= →HMS(37°55′55″); END;

I need a better way to control if the list Long_Lat {} is not void and has two elements with correct format: {-14°30′40″, 37°55′55″} (or almost two reals)...

thank you
Salvo


RE: How to control if a list isn't void? - Helge Gabert - 07-02-2015 01:32 AM

I would simply test (with "type()") if your HMS construct or your pair of reals belongs to DOM_SPECIALFLOAT or DOM_FLOAT, respectively (works in CAS).


RE: How to control if a list isn't void? - salvomic - 07-02-2015 05:32 AM

(07-02-2015 01:32 AM)Helge Gabert Wrote:  I would simply test (with "type()") if your HMS construct or your pair of reals belongs to DOM_SPECIALFLOAT or DOM_FLOAT, respectively (works in CAS).

I'll try, thank you!


RE: How to control if a list isn't void? - Helge Gabert - 07-02-2015 02:20 PM

When I tried it, I realized you need to convert into a string as well, i.e.

string(type(7°30'))==string(DOM_SPECIALFLOAT) returns 1.


RE: How to control if a list isn't void? - salvomic - 07-02-2015 02:26 PM

(07-02-2015 02:20 PM)Helge Gabert Wrote:  When I tried it, I realized you need to convert into a string as well, i.e.

string(type(7°30'))==string(DOM_SPECIALFLOAT) returns 1.

I want save into →HMS() format...
I'm using this in my astronomy program: the initial input asks to save coordinates, if the user chooses yes it saves into an exported var, otherwise it set a default couple of coordinates, then if the var exists, the program load the var into two fields and set two vars (lat, long)...

Maybe to control only for type it's enough (why someone should change a var exported by the program?), but...