Guessing variable type

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Guessing variable type

Post by MaxV » Mon Jun 17, 2013 5:19 pm

Hi again,
I read that there are the is a ... operator to guess is variable is a:
  • array
  • boolean
  • color
  • date
  • integer
  • number
  • point
  • rect
but is there an operator that return directly what type of variable is? Like:

Code: Select all

put 3 into temp
type? temp
and return number! :-D
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Guessing variable type

Post by Klaus » Mon Jun 17, 2013 5:31 pm

Hi Max,

no, there isn't.


Best

Klaus

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Guessing variable type

Post by shaosean » Tue Jun 18, 2013 6:05 am

You could always write a function to do it..

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Guessing variable type

Post by MaxV » Tue Jun 18, 2013 9:18 am

Ok, I tried this:

Code: Select all

function type? var
   if var is an array then
      return "array!"
   end if
   if var is a boolean then
      return "boolean!"
   end if 
   if var is an integer then      
      return "integer!"
   end if
   if var is a number then
      return "number!"
   end if
   if var is a point then
      return "point!"
   end if
   if var is a rect then
      return "rect!"
   end if
     if var is a color then
      return "color!"
   end if
      if var is a date then
      return "date!"
   end if
end type?
But how can I discriminate between string and date?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Guessing variable type

Post by shaosean » Tue Jun 18, 2013 11:00 am

if it is a date, then it is not a string ;-)

Post Reply