CONVERT and variables for arguments - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: CONVERT and variables for arguments (/thread-4952.html) Pages: 1 2 |
CONVERT and variables for arguments - epp - 10-15-2015 06:16 PM Too bad CONVERT doesn't support variables for arguments. Anyone have a code for a conversion utility? Code:
Update 26 Oct 2015: My first PRIME program and, over the last week, it has evolved to this solution. RE: CONVERT and variables for arguments - eried - 10-15-2015 07:05 PM You can experiment with CAS.EVAL("something") and cat(var1,var2,var3...) RE: CONVERT and variables for arguments - Han - 10-15-2015 07:08 PM Code:
Is this what you meant? RE: CONVERT and variables for arguments - epp - 10-15-2015 07:46 PM Sure is! Thank you, Han. It was my first program and you should see me smile! RE: CONVERT and variables for arguments - StephenG1CMZ - 10-15-2015 09:25 PM I found it gave a syntax error on 1 inch. Fixed by changing to 1 in. Both with underscores. Works good apart from inch conversions. RE: CONVERT and variables for arguments - Han - 10-15-2015 09:31 PM You might also find this post useful: http://www.hpmuseum.org/forum/thread-2913-page-2.html This allows you to turn the [Shift] [Space] key sequence to bring up a custom units menu (read further into the thread to see how to allow pressing [Esc] to just print an underscore character. RE: CONVERT and variables for arguments - epp - 10-16-2015 01:14 PM Here's the final version. I've also done Volume and Weight conversions using this as a template. Code:
RE: CONVERT and variables for arguments - eried - 10-17-2015 01:40 PM "mm","cm","m","km","inches","feet","yards","miles" can go in a list variable so you don't need to duplicate them RE: CONVERT and variables for arguments - epp - 10-17-2015 02:13 PM (10-17-2015 01:40 PM)eried Wrote: "mm","cm","m","km","inches","feet","yards","miles" can go in a list variable so you don't need to duplicate them Thanks. Somehow I knew it wasn't final. RE: CONVERT and variables for arguments - epp - 10-17-2015 10:03 PM Added the list for the menu, called expr instead of CAS (is CAS a better alternative here?), and simplified by removing "simplify". Code:
RE: CONVERT and variables for arguments - Han - 10-18-2015 01:19 AM (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". 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(). RE: CONVERT and variables for arguments - epp - 10-18-2015 05:52 AM 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:
RE: CONVERT and variables for arguments - StephenG1CMZ - 10-19-2015 01:18 PM (10-17-2015 01:40 PM)eried Wrote: "mm","cm","m","km","inches","feet","yards","miles" can go in a list variable so you don't need to duplicate them One option to avoid typing in duplicate lists is to assign "menu :=units", which saves having to type in all the units in the menu. You end up having units like " 1 mm" instead of "millimetres" - that's not pretty, but on the other hand its workable with less typing AND there is no risk of the two lists getting out of step, which could otherwise risk turn your "miles" into mm (if the two lists end up in different sequences). The disadvantage is you then have to go online to discover that an "lyr" is actually a light year. If you do keep the printable names as well as the units, if the lists can be changed to: Mm,"millimetres" Yds,"yards" //keep adjacent They are less likely to go wrong than if you have Mm,rods,chains,furlongs,yds "Mm"',chains"," rods","furlong","yards" It may also be worth pointing out that Han's technique does not extend to Temperatures, because of the differing zeros, in case anyone is tempted to do that. RE: CONVERT and variables for arguments - StephenG1CMZ - 10-21-2015 09:26 AM I have now incorporated this capability into my ZIPP program. I have made some usability changes. I changed the sequence to prompt for from units first... What's the point in typing 12 for 12cm before you have checked the program does cm: it might only do mm and m. This also means the units can be included in the input value prompt. Doing it the other way round, it was easy to tap the wrong units and get no warning, particularly since my screen is smaller than recommended. I have noticed that some HP units give an inconsistent units error - I wonder whether IFERR would trap these cases? (update: yes it can) Hope you find this program useful (there are some units not included). RE: CONVERT and variables for arguments - epp - 10-21-2015 10:14 AM I like your suggestions Stephen. I often have better luck pressing the number keys to make a selection. Code:
RE: CONVERT and variables for arguments - StephenG1CMZ - 10-21-2015 11:26 AM (10-21-2015 10:14 AM)epp Wrote: I like your suggestions Stephen. My own preference is to have the INPUT value between the two units... It seems confusing to me to select " to m" and then start typing in a value in mm rather than m (where mm is the from unit). As a user, I'm sure I would sometimes type in the value using "to units" instead by mistake. And the from and to screens are so similar its not always obvious that you have moved from from to to. Having the sequence " from, value, to" seems much clearer to me. Compare with the sequence in ZIPP and let me know what you think. RE: CONVERT and variables for arguments - epp - 10-21-2015 01:14 PM What is ZIPP? RE: CONVERT and variables for arguments - StephenG1CMZ - 10-21-2015 01:23 PM (10-21-2015 01:14 PM)epp Wrote: What is ZIPP? My collection of practical programs, now including unit conversions. I have just placed it in the HP Prime software library. RE: CONVERT and variables for arguments - epp - 10-21-2015 03:06 PM Ah, I see I'm re-inventing the wheel. I suspected as such since this is one of the things on older calculators that's missing from the PRIME. Either way works well. RE: CONVERT and variables for arguments - StephenG1CMZ - 10-21-2015 03:50 PM (10-21-2015 03:06 PM)epp Wrote: Ah, I see I'm re-inventing the wheel. I suspected as such since this is one of the things on older calculators that's missing from the PRIME. Either way works well. Not at all. Its thanks to your and Han's contributions on this thread that I got started on the Convert utility in my program...apart from me adding a few usability tweaks, most of the effort was typing in all those units - given that the hard part of sorting out how to do a conversion was already solved here. Thanks to both of you. It would be nice if a list of those units were available from HP (accessible from the code). I know I haven't included them all. |