Jump to content

Recommended Posts

Posted

Does anyone know how to check if a variable is a string or real number?

 

example

 

(setq ftemp(getreal "\n Select the Variable or Enter new value  (F1:/F2:)"))

 

 

 

Thanks

Posted

use the type function

(setq x 1.00)

(type x) returns real

(setq y "string")

(type y ) returns string

Posted

The type function perhaps?

 

[ John beat me by mere seconds... ]

Posted

john 1

Lee 0

but you get an "atta a boy" for showing up

Posted

You'll need the initget to sort this out:

(initget "F1 F2")
(setq ftemp (getreal "\nSelect the Variable or Enter new value [F1/F2]: "))

Unfortunately initget doesn'twork with anything but A-Z, a-z, 0-9 and -. So the : won't be shown. Anyhow, if the user enters a number that would be returned. If they press F and space a message is shown stating:

Ambiguous response, please clarify...
F1 or F2? 

It will only allow F1 or F2 if not a number. It's also case insensitive, so even if the user enters f1 the value would still be F1. So now to check what's been entered:

(cond
 ((eq ftemp "F1")
   (print "You've entered F1")
 )
 ((eq ftemp "F2")
   (print "You've entered F2")
 )
 ((= (type ftemp) 'REAL)
   (print (strcat "You've entered a new value " (rtos ftemp)))
 )
 ((not ftemp)
   (print "You've just pressed space / enter without typing anything")
 )
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...