cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Units in Slider

ppal
17-Peridot

Units in Slider

Hi

How do I put units into a slider?

ppal_1-1731446606342.png

Thank you

ACCEPTED SOLUTION

Accepted Solutions
DJNewman
17-Peridot
(To:ppal)

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...

 

DJNewman_0-1731462794312.png

 

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.

View solution in original post

6 REPLIES 6
DJNewman
17-Peridot
(To:ppal)

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...

 

DJNewman_0-1731462794312.png

 

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
StuartBruff
23-Emerald III
(To:DJNewman)

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 ... 😈

 

2024 11 14 C.png

 

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 ...  

 

https://community.ptc.com/t5/Mathcad/Programmatically-create-variable-names-and-assign-values-from/m-p/667321/highlight/true#M190290

 

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.

Werner_E
25-Diamond I
(To:StuartBruff)

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.

Werner_E_0-1731634711456.png

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

Werner_E_1-1731637126620.png

 


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 😉

StuartBruff
23-Emerald III
(To:Werner_E)


@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!

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
StuartBruff
23-Emerald III
(To:DJNewman)


@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

Announcements

Top Tags