DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Call COM Server and CreateObject

This could en up being multiple things, but it's all related.

There's a program I found called FluidProp that runs as a COM Server and will access Refprop, a database for fluid information. Thats all cool.

So now, I want to within Diadem call this FluidProp.

I have a full sample VBS that I'm trying to convert parts of to work within Diadem, realizing VBscript and VBS are different.

My knowledge of VBScript is limited to Excel environment. 🙂

 

But I want to start with the object creation and calls that do the grunt work. If I get that converted right, I can handle the rest I think.

 

The Object Creation:

Dim FluidProp As New FluidProp
Call FluidProp.CreateObject("RefProp", ErrorMsg)
  If ErrorMsg = "No errors" Then
  OutText = "RefProp object created..."
  RefProp_Available = True
Else
  OutText = "Unable to create RefProp object!"
  RefProp_Available = False
End If

 

 

Various VB calls for information: (I presume the conversion for one would work for the others)

Call FluidProp.GetFluidNames("l", "RefProp", nFluids, FluidNames, ErrorMsg)

Call FluidProp.SetFluid("RefProp", 2, Comp, Conc, ErrorMsg)

Call FluidProp.Pressure("PT", P, T, Output, ErrorMsg)

 

Thanks!

 

0 Kudos
Message 1 of 13
(6,435 Views)

Hi sg000,

 

If you go to Help>>Contents in DIAdem, this will bring up the DIAdem Help. Under Programming References>>General Information on Scripts you can find information about using the CreateObject Method in VBS. I think this would be a good place to start!

 

 

Julia P.
0 Kudos
Message 2 of 13
(6,412 Views)

@Jupiter02 wrote:

Hi sg000,

 

If you go to Help>>Contents in DIAdem, this will bring up the DIAdem Help. Under Programming References>>General Information on Scripts you can find information about using the CreateObject Method in VBS. I think this would be a good place to start!

 

 


Sorry, but not enough info there to make it work. I've tried a bunch of variants of 

Set RP = FluidProp.CreateObject(FluidProp.RefProp)

and all I continue to get on debug/run is an Error Object Required: "

Not a clue where to go from here.

0 Kudos
Message 3 of 13
(6,410 Views)

 

Here are some ideas, 

 

Maybe you have already tried these, but I am posting this just in case it is new.

 

Did you add the type selection under the script tab for the com object you are wanting.  The attached word document shows where this in in 2014.  Included in that word doc is a usage for connecting to Excel with a similar system.

 

Paul 

 

 

0 Kudos
Message 4 of 13
(6,406 Views)

 

@Pesmith8 wrote:

 

Here are some ideas, 

 

Maybe you have already tried these, but I am posting this just in case it is new.

 

Did you add the type selection under the script tab for the com object you are wanting.  The attached word document shows where this in in 2014.  Included in that word doc is a usage for connecting to Excel with a similar system.

 

Paul 

 

 


Thanks. That is helpful. Didn't know about the selection that needed to be done in Diadem. Even added it to the top of my script. That debugs ok.

' FluidProp 2.0 Type Library
' C:\Program Files\FluidProp\FluidProp.dll\1
'Call AutEdTypeLibAdd("A2D7D57A-357D-4DF5-BAB2-79F05DED3E33", "2.0")
Call AutEdTypeLibAdd("C:\Program Files\FluidProp\FluidProp.dll", "2.0")
' RefProp 2.1 Type Library
' C:\Program Files\FluidProp\RefPropCOM.dll\1
'Call AutEdTypeLibAdd("0A5D9758-CD14-4B8F-8A65-3A5797C90A24", "2.1")
Call AutEdTypeLibAdd("C:\Program Files\FluidProp\RefPropCOM.dll", "2.1")

 

However, it only midly improved the situation. Now I get ActiveX cannot create object errors. "ActiveX Component Cannot create Object"

I've tried these variants:

 Set RP = CreateObject("FluidProp.Application")
 Set RP = CreateObject("FluidProp")
 Set RP = CreateObject("FluidProp", "Refprop")

 

If I try another function I get Type Mismatch and the function name

 Call SetFluid("RefProp", 1, "R410a", 1, ErrorMsg) 

 RP = GetFluidNames("s", "all")

 

Also no code completion for any of the supposed included functions/subs for these dlls.

 

I downlaoded a software that checks registration, also manually viewed in regedit. They are listed.

 

I've written to the FluidProp people for VBscript support since they support VB, no response yet.

 

 

 

0 Kudos
Message 5 of 13
(6,396 Views)

Hi sg000,

 

You can not "Dim VarName As" in a VBScript.  You have to first create an object variable from the external class, like this:

 

Set FluidPropObj = CreateObject("FluidProp.RefProp")

I don't know if that's really a valid library on your computer, but the above is the correct syntax in VBScript to create an object variable from an external class.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 6 of 13
(6,368 Views)

@Brad_Turpin wrote:

Hi sg000,

 

You can not "Dim VarName As" in a VBScript.  You have to first create an object variable from the external class, like this:

 

Set FluidPropObj = CreateObject("FluidProp.RefProp")

I don't know if that's really a valid library on your computer, but the above is the correct syntax in VBScript to create an object variable from an external class.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments



Thanks Brad. Unfortunately, that provides the error: "ActiveX component can't create object: 'FluidProp.RefProp'

And anything I try and put as arguments for the CreateObject results in that same message.

Doing some research returns a bunch of 64bit vs 32 bit configuration issues, well im running 32 bit on a 32 bit, so thats not the issue.

 

This does work, so I know at least CreateObject can work:

Call AutEdTypeLibAdd("C:\WINDOWS\system32\scrrun.dll")
Call CreateObject("Scripting.FileSystemObject")
Call MsgBoxDisp("Constant ForWriting= " & ForWriting) ' ForWriting = 2

 

FluidProp is in the registry, I even tried registering it again. 

Authors of the software are being only a little help. They referred me to their Excel example:

Public FP As New FluidProp

and then calls the StanMix library (which has the same status as RefProp) by:

     Call FP.StanMix_Psat_k1(k1, T, Psat, ErrorMsg)

 Well, we know the "As New" isn't legal for Diadem. And as a result the FP.StanMix.... doesn't work either.

If I at least Dim all those variables I get a "Object Required" error.  Ugh.

0 Kudos
Message 7 of 13
(6,352 Views)

Hi SG00, 

 

I have had a similar issue with a program would operate in VBA in Excel but not in DIAdem. Maybe this can still work.

 

A program that I like to use to look at DLL's is Dependency Walker,  It is free from Microsoft.  What this program does is lets you look at the functions inside a DLL.  Lets you know the parameters and somewhat how to call it.  Maybe what it shows you about the DLL will be helpful.  It also shows what other DLL's are needed for the dll to work, (its dependencies and whether they are present and can be found on that machine.) Sometimes this has helped me know that it was not the dll that was the issue but a sub DLL that it needed.

 

Just a little background on VBA which is used in Excel. It is fairly close to VB 6.0 which came out in 1998 time frame. 

 

One other note, Does the DLL work inside of Excel?  (Just mentioning this to verify that the Computer setup is OK) 

 

Did the company give you any lib files or prototypes for how to call the functions. 

 

 

Best Wishes on this tough task, 🙂

 

 

Paul

 

 

Message 8 of 13
(6,348 Views)

Had some success today with the help from the guys at Asimptote who wrote the FluidProp wrapper. 

This part of the Diadem code works and gives me an actual object to reference, sets up the variables ready for the important calls.

 

Option Explicit
Dim OutText
 Dim Output
Dim ErrorMsg
OutText = ""
Output = 0.000
ErrorMsg = ""

Dim FluidP, RefP
Set FluidP = CreateObject("FluidProp.FluidProp")
Set RefP = CreateObject("RefProp.RefProp")

' Number of components equals number of concentrations
Dim Num_Comps
Num_Comps = 1

Dim Comp
Comp = Array("Air")

Dim Conc
Conc = Array(1)

But now each of these sub calls gives a Type Mismatch:

     Call FluidP.SetFluid("StanMix", Num_Comps, Comp, Conc, ErrorMsg)
     Call FluidP.SetFluid("RefProp", Num_Comps, Comp, Conc, ErrorMsg)
     Call FluidP.Pcrit(Output, ErrorMsg)
     Call FluidP.Pressure("PT", 1.0, 15.0, Output, ErrorMsg)

And the Deifnitions for those in Code Completion are:

 

Sub SetFluid(ModelName As String,nComp As Int, ByRef As StringArray, ByRef Conc As Unknown, ByRef ErrorMsg As String)

Sub Pressure(InputSpec As String,Input1 As Double, Input2 As Double, ByRef Output As Double, ByRef ErrorMsg As String)

Sub Pcrit(ByRef P_crit As Double, ByRef ErrorMsg As String)

 

I've been trying to search through the forums for type mismatch posts, but haven't come up with anything that matches just right yet.

 

--Scott

 

 

 

0 Kudos
Message 9 of 13
(6,329 Views)

Hi Scott,

 

This is why COM objects are preferable for VBScript.  Those explicit data typed prameters won't work in a VBScript, where are variables are of type=Variant.  The COM object wraps up the code with all Variant input and output parameters.  Perhaps your contacts can provide you with a COM wrapper for this DLL.

 

Alternatively, you could call the external code with a LabVIEW VI and run that VI from the DIAdem VBScript using the LVRuntime object.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 10 of 13
(6,322 Views)