Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hi All,
I would like to obtain a value of a variable from my worksheet. Let say my worksheet has x:=1 and y:=x+1=2. What function can I use to get the y value? I was trying with Worksheet.OutputGetRealValue(&As)("y") but I got an error instead. The following is my code:
Sub test01()
Dim WS As Ptc_MathcadPrime_Automation.Worksheet
Dim App As Ptc_MathcadPrime_Automation.Application
Set App = New Ptc_MathcadPrime_Automation.Application
FileName = Application.GetOpenFilename(MultiSelect:=False)
Dim conNum As Integer
i = 22
conNum = Cells(i, 7)
Do While Cells(i, 1).Value <> ""
'' inputs
Set WS = App.Open(FileName)
Call WS.SetRealValue("#", Cells(i, 7), "")
Call WS.SetStringValue("M1", Cells(i, 2))
'Call WS.SetStringValue("M2", Cells(i, 4))
Call WS.SetStringValue("M3", Cells(i, 3))
Call WS.SetStringValue("M4", Cells(i, 1))
Call WS.SetRealValue("D2", 3, "")
Call WS.SetRealValue("D3", 3, "")
Call WS.SetRealValue("D4", 3, "")
Call WS.SetRealValue("D1", 3, "")
Call WS.SetRealValue("P1", Cells(i, 5), "kip")
'Call WS.SetRealValue("P2", 10, "kip")
Call WS.SetRealValue("P1", Cells(i, 6), "kip")
Call WS.SetRealValue("T1", Cells(i, 8), "in") '' need to be added
'' check all checks
WS.ResumeCalculation
If WS.OutputGetStringValue("check1") <> "OK" Then
Debug.Print ("check1:= not ok")
End If
Do While WS.OutputGetStringValue("check2") <> "OK"
N = WS.OutputGetRealValue("D2")
D2 = CDbl(WS.OutputGetRealValue("D2"))
Call WS.SetRealValue("D2", D2 + 1, "")
I would like to manipulate D2 value, how do I do that?
Also, is it correct how I use OutputGetStringValue function? the "check2" in my worksheet is "check2="OK""
Thank you very much!!
Solved! Go to Solution.
Hi,
Let say my worksheet has x:=1 and y:=x+1=2. What function can I use to get the y value?
First express y as a simple display value:
y=
This will display y=4
highlight it and select Input/Output | Integration | Assign Outputs
A small blue box with the title Out will display around y=4
Note it is the first output and I have manually changed the alias text to y
Dim y As String
Dim y_val As Ptc.MathcadPrime.Automation.IMathcadPrimeOutputResult
Outputs = WS.Outputs
y = Outputs.GetAliasByIndex(0)
y_val = WS.OutputGetRealValue(y)
Cheers
Terry
Hi,
Let say my worksheet has x:=1 and y:=x+1=2. What function can I use to get the y value?
First express y as a simple display value:
y=
This will display y=4
highlight it and select Input/Output | Integration | Assign Outputs
A small blue box with the title Out will display around y=4
Note it is the first output and I have manually changed the alias text to y
Dim y As String
Dim y_val As Ptc.MathcadPrime.Automation.IMathcadPrimeOutputResult
Outputs = WS.Outputs
y = Outputs.GetAliasByIndex(0)
y_val = WS.OutputGetRealValue(y)
Cheers
Terry
Hi,
Dim y_val As Ptc.MathcadPrime.Automation.IMathcadPrimeOutputResult
y_val has three members
y_val.ErrorCode an int32
y_val.RealResult a Double
y_val.Units a String
Cheers
Terry
So, we refer to output by index in the I/O list and not alias name?
thank you very much!
For me, this only work when
Set y_val = WS.OutputGetRealValue(y)