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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Textbox input dimension with units

ptc-2712887
1-Visitor

Textbox input dimension with units

I am using textboxes for user input in my mathcad worksheet (a text box is required for other programmed reasons so this cannot be changed).

The user needs to be able to input a number (dimension) with units; i.e. 3in.

I wondered if anyone knows a way I can pull this input apart to go from "3in" to 3*in.
(I currently have it working without the units. So I can got from "3" to 3 but the units are throwing me off).

I was thinking I could set up something and compare it to its KeyAscii value. But I think I am in over my head on this one. Not really sure how to approach it.


any help. suggestions. hints. will be really appreciated!
7 REPLIES 7

The 'obvious' suggestion is that you may need two
input boxes, one text (numerical) for the number,
and one a list for the units you provide, probably
using a hidden function that simply applies the
appropriate scaling.

if (text=="in") result=input*in
if (text=="cm") result=input*cm
...
return result


Philip Oakley

Next obvious suggestion is that instead a text box the second input could be better a list box with predefined in, ft, m, cm, years light, etc, which answer the adequate conversion factor. So, if q1 is the out of first text box user input and u1 is the output for the second list box user input you set always q := q1*u1*meters as the total user input.

The other suggestion is the following: there are a lot of unit conversion utilities for excel scripted as vba macros. You can try to convert this into vbs. There are a lot of differences between both languages (vba = visual basic for applications, vbs = idem, but script), but with enough effort you can have sucess. This is -I think- the only way to handle inputs as "3 in" as only one string.

Regards. Alvaro.

Try the define variables control ( http://collab.mathsoft.com/read?112283,11 ). You will need to split the input into the leading number and the units, but that shoud be fairly easy in VBS.
__________________
� � � � Tom Gutman
StuartBruff
23-Emerald III
(To:ptc-2712887)

On 12/21/2009 11:58:38 AM, aes4130 wrote:
== I am using textboxes for user input in my mathcad worksheet (a text box is required for other programmed reasons so this cannot be changed).
== The user needs to be able to input a number (dimension) with units; i.e. 3in.
== I wondered if anyone knows a way I can pull this input apart to go from "3in" to 3*in.
== (I currently have it working without the units. So I can got from "3" to 3 but the units are throwing me off).

A quick think about the problem suggests that your textbox will have to return either a single string for Mathcad to handle, or you need to get the textbox to return the numeric value and the unit as separate strings - I don't think there is a means of getting a textbox to return a dimensioned result.

Given this, you're probably better off returning a single string and getting Mathcad to parse it and convert as necessary - you're more likely to find you can reuse the Mathcad code for something else.

For example, see attached. The provided function, takes a string, splits it into numeric and unit strings, then uses a lookup system to get the unit equivalent of the unit string.

Stuart

Wow. That is a really nice worksheet. It might take me a while to absorb it all.

It is a different approach than I was taking. I was attempting to contain all the work in the textbox script.

But this seems like a workable approach.

Thank you for sharing this with me.


Amy
StuartBruff
23-Emerald III
(To:ptc-2712887)

On 12/21/2009 4:31:05 PM, aes4130 wrote:
== Wow. That is a really nice worksheet. It might
take me a while to absorb it all.

No worries.

== It is a different approach than I was taking. I
was attempting to contain all the work in the
textbox script.

You could do that, it's straightforward enough,
but you're still left with the problem of dealing
with the units. This can either be done
externally, as I've done, or you can do it by
using Tom's technique, which is far more general.
I've sort of combined a bit of both on the
attached worksheet.

Stuart

Note: this won't work in Mathcad 11 and I haven't
tried it in M12 or M13.
Announcements

Top Tags