Post Reply 
CONVERT and variables for arguments
10-18-2015, 01:19 AM
Post: #11
RE: CONVERT and variables for arguments
(10-17-2015 10:03 PM)epp Wrote:  Added the list for the menu, called expr instead of CAS (is CAS a better alternative here?), and simplified by removing "simplify".

Code:

EXPORT CD2,CD1;
EXPORT Distance()
BEGIN
  LOCAL x,menu,unit,a1,a2,t;
  INPUT({{ x,[2],{45,20,3} }},"","Convert ");
  IF string(x,1) == "0" THEN RETURN; END;
  unit := { 1_mm, 1_cm, 1_m, 1_km, 1_inch, 1_ft, 1_yd, 1_mile };
  menu := { "mm","cm","m","km","inches","feet","yards","miles" };
  CHOOSE(CD2, "Units", menu);
  CHOOSE(CD1, "To", menu);
  a2 := unit[CD2];
  a1 := unit[CD1];
  t := x + "*" + CONVERT(a2,a1);
  expr(t);
END;

You don't want to use EXPR() -- you want CAS() because it will allow for undefined variables in addition to defined variables and numerical values for x. EXPR() expects everything to be resolvable and will return an error if there is a reference that cannot be resolved. On the other hand, if you know that you will never want to create something like t_m where t is an undefined variable, then stick with EXPR().

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
CONVERT and variables for arguments - epp - 10-15-2015, 06:16 PM
RE: CONVERT and variables for arguments - Han - 10-18-2015 01:19 AM



User(s) browsing this thread: 1 Guest(s)