bgator220 Posted October 2, 2010 Posted October 2, 2010 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 Quote
JohnM Posted October 2, 2010 Posted October 2, 2010 use the type function (setq x 1.00) (type x) returns real (setq y "string") (type y ) returns string Quote
Lee Mac Posted October 2, 2010 Posted October 2, 2010 The type function perhaps? [ John beat me by mere seconds... ] Quote
JohnM Posted October 2, 2010 Posted October 2, 2010 john 1 Lee 0 but you get an "atta a boy" for showing up Quote
Lee Mac Posted October 2, 2010 Posted October 2, 2010 john 1Lee 0 but you get an "atta a boy" for showing up lol Quote
irneb Posted October 2, 2010 Posted October 2, 2010 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") ) ) Quote
Recommended Posts
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.