Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
I'm often provided with a flow rate, but it can be specified in either volume flow or mass flow. I want a simple way for my sheets to work regardless of what is specified (i.e. calculate the one that isn't defined from the other). My goal is to have the two inputs, but the one I don't need is disabled. I thought this would be easy, but I'm not finding a solution other than to enable/disable equations (which could get messy and dangerous) or assign flags telling mathcad what to do (also dangerous). In excel I could use ISNUMBER or similar, but I don't seem to find that in Mathcad. I thought TRY would work, but even that quits when it reaches an undefined variable. I tried a few things with NaN but still no luck. Any suggestions? Thanks.
4.0 attached.
Solved! Go to Solution.
What might work would be to predefine both flow rates negative. (You could put this at the top in a closed area so it doesn't show.) Down where it matters you define the one you have, then a simple if statement will do what you want.
Prime 4.0 attached
AFAIK there is no way to check if a variable already has been assigned a value.
You may set a variable to NaN and check using IsNaN(variablename).
Or you may set the variable to Zero or to string saying "not assigned" and check for that.
The point is, that the variable must have been assigned any value if you intend to use it in your routine.
Prime does not a function to determine is a variable is defined. Attached is snippet that is a work around, but not a complete solution.
Cheers
What might work would be to predefine both flow rates negative. (You could put this at the top in a closed area so it doesn't show.) Down where it matters you define the one you have, then a simple if statement will do what you want.
Prime 4.0 attached
Thanks Fred. A bit unusual but that should work. A slight improvement would be to define them as imaginary numbers instead of negatives. Either way works but if you started with multiple streams and adding flows, a negative could get lost. However I'm unlikely to have a imaginary flow rate.
In my opinion NaN would be a more "natural" initial assignment compared to negative or non-real numbers (with units!?), because NaN tells the whole story - its "not a number". Using that variables in calculations with units should not throw any error and any calculation done with them should result in NaN, too, so its easy to spot.