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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! 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

10 REPLIES 10
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

StuartBruff
23-Emerald III
(To:StuartBruff)

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.

 

2024 11 22 A.png

 

Stuart

ppal
17-Peridot
(To:StuartBruff)

@StuartBruff Thank you!

Werner_E
25-Diamond I
(To:StuartBruff)

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

Werner_E_0-1732244233445.png

For some fun you may change "quantity" in the script of the unit selector to "value" - Prime does not prevent doing so 🙂

 

StuartBruff
23-Emerald III
(To:Werner_E)

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.

 

https://support.ptc.com/help/mathcad/r10.0/en/?utm_source=mathcad/index.html#page/PTC_Mathcad_Help/API/example-8_vbscript.html#

 

5. In the worksheet, note the two input regions that define the input1 and matrixInput1 variables. Click OK to dismiss this window.
6. Windows Script Host notification window opens informing you the API uses the SetRealValue method to change Input1 from 45 kg to 12.2341 km. Click OK to dismiss this window.
7. The value of Input1 changes to 12.2341 km. A Windows Script Host notification window opens showing the number of output regions in the worksheet, and the alias for the first output. Click OK to dismiss this window.
 
A solution to the "units in slider" problem was immediately obvious and that was as far I wanted to take it, my brain cell having done its work for the week.
 
It also offers a route to solving another long-standing question -- how to import units from Excel/whatever.
 
Allowing an advanced control to be the body of a function will simplify things all round.
 
Stuart

 

Announcements

Top Tags