Post Reply 
CONVERT and variables for arguments
10-18-2015, 05:52 AM (This post was last modified: 10-18-2015 03:45 PM by epp.)
Post: #12
RE: CONVERT and variables for arguments
Ahh, I only intended to have numeric input. My fault for not mentioning this. Well, with this in mind things got a bit simpler. The reason my original code didn't work was because I was concatenating to create the 1_ object rather than simply specifying the object directly in the list. This created a string containing the of the name of the object and that wouldn't work unless it was evaluated via expr or cas.

In summary, CONVERT does accept variables for arguments but those variables must contain an appropriate object. I wish to thank both Han and Eried for their patience and assistance.

Code:

EXPORT CDFrom,CDTo;
EXPORT Distance()
BEGIN
  LOCAL x,menu,unit;
  INPUT({{ x,[0],{45,20,3} }},"","Convert ");
  IF x == 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(CDFrom, "Units", menu);
  CHOOSE(CDTo, "To", menu);
  x*CONVERT(unit[CDFrom],unit[CDTo]);
END;
Visit this user's website 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 - epp - 10-18-2015 05:52 AM



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