comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How to see if variable is defined?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: How to see if variable is defined? [message #3411 is a reply to message #3359] Thu, 26 January 1995 03:18 Go to previous messageGo to previous message
nmw is currently offline  nmw
Messages: 18
Registered: January 1995
Junior Member
In article 95Jan20094331@venice.water.ca.gov, rfinch@water.ca.gov (Ralph Finch) writes:
> Is there a nice way of checking if a variable is defined?
>
> I have a widget_control command which removes a menu, and I need to
> see if the menu is defined before destroying it.
> --
> Ralph Finch 916-653-8268:voice 916-653-6077:fax
> rfinch@dop.water.ca.gov / finger for PGP public key
> "Nada burra la chamaca." A.G.
> Any opinions expressed are my own; they do not represent my employer


There are two possible ways of doing this.

The first is to use the keyword_set function. This returns 1 if a variable
is defined, 0 otherwise. Use of this function to test for a variable being
defined is not recommended and is bad practice - it is meant to test for
the existence of a keyword in a function call, it happens to work.

The proper way is to use the size function. This returns a vector describing
the attributes of a variable. Unfortunately it is a variable length vector
which can make programming using it quite tedious. However, just to check
if a variable is defined is quite simple. The second element of the vector
is the data type of the variable, which is zero if the variable is undefined.

Thus, the code

IF (SIZE(variable))(1) EQ 0 THEN BEGIN
PRINT,'Undefined'
ENDIF ELSE BEGIN
PRINT.'defined'
ENDELSE

should tell you what you want to know.


---
------------------------------------------------------------ ------
Nigel Wade | E-mail : nmw@ion.le.ac.uk
System Administrator |
Ionospheric Physics Group | phone : +44 (0)116 2523568
University of Leicester |
Leicester, LE1 7RH, UK | fax. : +44 (0)116 2523555
------------------------------------------------------------ -------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: autostart Wave license, Solaris 2.4
Next Topic: "True" map projections

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:35:50 PDT 2025

Total time taken to generate the page: 0.00246 seconds