Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
You can't directly put units on any advanced control...
...But what you will see on PTC's own worksheets would be something like
x: [slider] and then x2 or xunits: x*cm.
And then you use xunits for any further calculation or input.
Edit: If the unit varies but you want to use the same slider every time, then... you can be a little more creative. I came up with something like this...
You can't directly put units on any advanced control...
...But what you will see on PTC's own worksheets would be something like
x: [slider] and then x2 or xunits: x*cm.
And then you use xunits for any further calculation or input.
Edit: If the unit varies but you want to use the same slider every time, then... you can be a little more creative. I came up with something like this...
Not that I wish to be contrary, but after pondering this matter for a few milliseconds (or thereabouts) 🤔. an obvious (for values of "obvious") solution occurs to me ... 😈
I'm not a huge user of units, but this was a requirement that I've had on occasion. Before Mathcad Prime 10, I went with a traditional lookup approach (see postscript). Now that Mathcad Prime 10 is here, I slotted in an advanced control to choose the unit (as did you) before passing it to the lookup function. However, a few minutes ago I spotted something in the advanced control Help that gave me an idea. And voilà (or whatever French for "look there" is).
The clue is there in the image ...
Stuart
What? Why, the very thought. Of course, I've suggested adding the Potrzebie System of Weights and Measures.
Hmm. I suspect the original request is hidden in deep time within the old Mathsoft Collaboratory, but an honourable mention goes to ...
How true. I'm surprised that no maintenance subscriber has asked for a modified version of str2num that converts quantified numeric strings (eg, "3.14159 mp" or 2.7Fb" (where mp = millipotrzebie and Fb = furschlugginer blintz )), so that we'd have:
str2num("3.14159 mp") = 7.111 μm
str2num("2.71828mp") = 99.014 t
I suppose some enterprising individual could probably write one ... (I think I may have one hidden deep in my M15 archive)
Yes, I did have such a variant of str2num, but it requires maintenance to make it more generally useful, so I'll wait for the revised str2num to appear as a priority upgrade in Mathcad Prime 11.
So you were kind enough to have the button "Show in Worksheet" pressed 😉
Clever idea and sure looks better than using 'lookup'. After all the vector unitsL isn't needed in your approach anyway.
I would rather use a listbox to choose the unit instead of using a slider (even if it would take up more vertical space or requires scrolling), but that may be just a matter of personal preference.
If the number of units to choose from is not too large, radio buttons may be an option as well. Unfortunately they can only be arranged in a column or in a row but not in matrix formation.
It may also be an option to define the value in front of the unit selector and use it as its second input
Yes, I did have such a variant of str2num, but it requires maintenance to make it more generally useful, so I'll wait for the revised str2num to appear as a priority upgrade in Mathcad Prime 11.
I am full of admiration for your unshakeable optimism!
Don't you think that MDAs, empty arrays, list data structure are further up the priority list?
But once advanced controls can be assigned to Prime functions and get implemented a way to return units as well similar to the API, it should be not that difficult to write your improved str2num yourself 😉
@Werner_E wrote:
So you were kind enough to have the button "Show in Worksheet" pressed 😉
I endeavour not to be too cruel and like to leave the odd hint lying around. 😇
Clever idea and sure looks better than using 'lookup'. After all the vector uniOtsL isn't needed in your approach anyway.
Nor am I sufficiently saintly as to not throw in a little misdirection. 😈
I would rather use a listbox to choose the unit instead of using a slider (even if it would take up more vertical space or requires scrolling), but that may be just a matter of personal preference.If the number of units to choose from is not too large, radio buttons may be an option as well. Unfortunately they can only be arranged in a column or in a row but not in matrix formation.
That would have been my first choice, but Dave had already used a ListBox, so I had to do something to add value to the thread.
Yes, I did have such a variant of str2num, but it requires maintenance to make it more generally useful, so I'll wait for the revised str2num to appear as a priority upgrade in Mathcad Prime 11.
I am full of admiration for your unshakeable optimism!
As they say (whoever "they" are), those who do not learn from history are doomed to repeat it. Some of us are just slow learners. Oder vielleicht haben wir unsere Zunge fest in unseren Wangen (nicht ernstgemeint?). Das eine oder das andere.
Oddly enough, my recent foray into Mathcad Prime Express 7 territory left me thinking both a) programming has weakened my recursion fu skills and b). MP10 makes MP7 feel positively archaic. I've become so used to Text Styles that I'd quite forgotten they were a recent (and most welcome) feature. Indeed, Advanced Controls are another feature that I've had recourse to of late. So, progress does occur, thus validating my optimism. 😁
Don't you think that MDAs, empty arrays, list data structure are further up the priority list?
Paraphrasing Ko-Ko from the great Gilbert and Sullivan's Mikado, "I have a little list, they've all of them been missed".
But once advanced controls can be assigned to Prime functions and get implemented a way to return units as well similar to the API, it should be not that difficult to write your improved str2num yourself 😉
It could probably already be done using an s-expression rewrite. But, I think the current solution probably meets @ppal's prima facie (or should that be "Prime facie") need. And I have higher priority game afoot.
Stuart
I proposed to use a Combo Box for picking units, actually!
@DJNewman wrote:
I proposed to use a Combo Box for picking units, actually!
So, you did, Dave. My apologies.
I’d like to say that will teach me to read a couple of messages further up a thread to see what was actually written, but, like I said, I’m a slow learner … a very slow learner.
Stuart
Sorry, @ppal . I'd meant to post this earlier but was waiting to see if anybody else could think of alternate ways to implement adding units from an advanced control.
Here's the JScript code for the units slider and the worksheet is attached. Hopefully, you'll still have to use it for your Frustum Challenge entry.
Stuart
How about exchanging the order of value and unit input and using the value as additional input for the unit slider?
That way this slider could directly generate the necessary quantity variable and so we could omit the "unit" variable as well as the output variable "strunit" (because we directly can see the chosen unit in the assignment of "quantity".
For some fun you may change "quantity" in the script of the unit selector to "value" - Prime does not prevent doing so 🙂
Sure, it's entirely up to whoever wishes to use the capability how they arrange and name things.
As background, I'd started to write the worksheet as a couple of variants of a standard lookup table, but while looking for something completely different, my eye was caught by the following API Help.
Allowing an advanced control to be the body of a function will simplify things all round.
That would be an urgently needed further development.
And a placeholder for a unit of the variable to which the control is assigned would also be appropriate in a program like Prime. This would also save us all these tricks and scripts.