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
Hello guys till now i found some examples for accesing Mathcad sheets and extracting outputs and it works.
The Problem is now i read here a lot about sth like that it is not possible to recalculate some sort of functions. Well I rewrited a code i found here and there is a small problem (maybe big not sure). Tried to get customer services and I have a ticket but ....have not that much of time to wait for them to call me (already one week passed).
Ok attached you can find my Mathcad sheet and everything works fine with it when i set the values. If i do it now with visual basic i get an error for getvalue:
What Im doing is to set some values in my Mathcad Sheet and in the end i have a function with minimize. I defined that function as "optimal" look here:
Well if i set the values in Mathcad everything works well and i have a solution. BUT if i do it with visul basic COMexception occurs. What is wrong here ? I mean if i set the values than i see in Mathcad its calculating around 5 sec. and bäm: comexception ....
Alright maybe someone here who knows or had this problem with the help in mathcad i couldnt find a solution sitting here since couple days and tried nearly everything ^^
I've never used the setvalue, but based on my understanding of this function I see three things wrong with your implementation:
I would suggest trying a more simplified setup. For example:
setvalue("a",1)
getvalue("b")
with your worksheet only having one equation: b:=a+1
Once you get that working, try including dimensions.
After that's working, try including subscripts.
Slowly add more complexity until you get your desired output.
Mark is correct. SetValue binds the variable prior to any variable definition in the worksheet, including global assignments. Any subsequent definition of the same variable overrides the binding from SetValue. SetValue does not support units.
You can do what you want, but to do so you must manipulate the XML of the math region. I've attached a worksheet that has some scripted components that show you how to do that in VBscript. VBscript is not VB.NET, but you should be able to port the code over to your application.
Hi many thanks for your answers so far but i dont reall understand it.
I tried it with a more simple one and it works :
As you can see it works and gives me just the value. On my worksheet not i think it has to do sth with the minimize function. My values are all "multiplied" to the value -.-' im so lost
Your simplified example works, but it does not use the units like you probably think it does.
First: unless you've defined PA above your screenshot, Mathcad is treating it as an undefined variable. I assume you intended the unit Pa.
In your Mathcad sheet, A:+_*PA does nothing. Same for B:=_*PA. You can delete those equations and get the same result. Setvalue("A",2) defines the variable "A" above the worksheet. When Mathcad gets to A:=_*PA, it ignores it because it's an incomplete equation.
Try changing your equation to C:= A+B*2.5+1*Pa
I expect that you'll get a unit incompatibility error because Mathcad sees A & B as unitless so it can't add 7+1*Pa.
If you want A to have units Pa, you need to setvalue("A",2), then in Mathcad define A:=A*Pa. Then, if you want to return C in Pa, you must define C:=C/Pa at the end of the worksheet (actually, this is unnecessary for Pa since that's the default unit of pressure, but you'd need to divide by your units for any non-standard units).
In Mathcad, change these two equations:
p.0:=_*Pa
k1:=_*Pa
to these:
p.0:=p.0*Pa
k1:=k1*Pa
Delete the equation n1:=_ because it is unitless (or change the equation to n1:=n1)
In VB, chnage SetValue("p0",myA) to SetValue("p.0",myA) -- (with a period between p & 0).
You use SetValue for two other variables that I don't see in Mathcad, so you can determine what to do with them.
Please post your worksheet (you will have to zip it first).