Jump to content



Featured Articles

Check out the latest featured articles.

File Library

Check out the latest downloads available in the File Library.

New Article

Product Viscosity vs. Shear

Featured File

Vertical Tank Selection

New Blog Entry

Low Flow in Pipes- posted in Ankur's blog

Hysys Link Vba

hysys vba dll

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic
Share this topic:
| More

#1 Fernando Bórquez

Fernando Bórquez

    Brand New Member

  • Members
  • 8 posts

Posted 24 February 2014 - 05:22 PM

Hi i'm triying to link VBA with hysys for calculate some thermodynamic properties of oil, i have to send temperature and pressure to hysys throught a macros for this calculate. Hysys library it's activate on VBA, when i run the code VBA returns me this message:

 

"Error in load dll library"     

 

My code is:

 

Option Explicit
Public hyApp As HYSYS.Application
Public simCase As HYSYS.SimulationCase
Public CRUDOBRM As HYSYS.ProcessStream
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
 
 
'Inicialización de Hysys
Public Sub Oleoducto()
''Variables de HYSYS''
Dim filename As String
Dim PressureHysys As Double
Dim TemperaturaHysys As Double
Dim VaporFractionHysys As Double
 
''Variables Ingresadas por Usuario''
Dim Caudal As Double 'Caudal de entrada en m3/dia
Dim Pinicial As Double 'Presión inicial en Kg/cm2
Dim Tinicial As Double 'Temperatura inicial
Dim Tambiente As Double 'Temperatura ambiental
Dim HeatLoss As Double 'Perdida de Calor Global
Dim dX As Double 'Paso de Integración del ducto
Dim Psucción As Double 'Presion de Succión Admitida
Dim Vmax As Double 'Velocidad Maxima Permitida
 
''Apertura de HYSYS para el cálculo de propiedades''
Set hyApp = CreateObject("HYSYS.Application")
    hyApp.Visible = True
    Set simCase = hyApp.ActiveDocument
    If simCase Is Nothing Then
        filename = Worksheets("Simulador").Range("c4")
        
        If filename <> "False" And simCase Is Nothing Then
            Set simCase = GetObject(filename, "HYSYS.SimulationCase")
            simCase.Visible = True
        End If
End If
 
Set CRUDOBRM = simCase.Flowsheet.MaterialStreams.Item("CRUDOBRM")
Cells(6, 6) = CRUDOBRM.Pressure.GetValue("PSGI")
 
End Sub

 

 

The thing it's Early Binding it's not function, with Late Binding i can open the simulation case but I can't manipulate the conditions of the process.

 

Please Help Me,

 

Thank's


Edited by Fernando Bórquez, 24 February 2014 - 05:27 PM.


#2 Bobby Strain

Bobby Strain

    Gold Member

  • Members
  • 3,529 posts

Posted 24 February 2014 - 05:45 PM

Be sure you have checked the library reference for the project. And you have to type the names and units exactly as HYSYS wants. "PSGI" won't be recognized. And I would use ActiveSheet.Range("A1").Cells(6, 6) to be sure you get the proper cell.

 

Bobby


Edited by Bobby Strain, 24 February 2014 - 05:48 PM.


#3 Fernando Bórquez

Fernando Bórquez

    Brand New Member

  • Members
  • 8 posts

Posted 24 February 2014 - 06:05 PM

Bobby thank's for your answer, i delete that line... I think the problem it's with library... The library reference its checked in the project. When i'm writing code seems that, but the error it's still there:

 

Set hyApp = CreateObject("HYSYS.Application")   ---> In this line specifically. (In debug mode)   hyApp=Nothing 

 

 

Rewards.



#4 Bobby Strain

Bobby Strain

    Gold Member

  • Members
  • 3,529 posts

Posted 24 February 2014 - 06:27 PM

Here is a working example from their support site.

 

Bobby

Attached Files


Edited by Bobby Strain, 24 February 2014 - 06:29 PM.


#5 Fernando Bórquez

Fernando Bórquez

    Brand New Member

  • Members
  • 8 posts

Posted 24 February 2014 - 07:20 PM

Error persist. 

 

Thank's for all.



#6 Bobby Strain

Bobby Strain

    Gold Member

  • Members
  • 3,529 posts

Posted 24 February 2014 - 09:37 PM

The code I sent works. To use it, you must reference the HYSYS library that is on your machine.  The reference in this workbook is to and older version of the library. Then, if you code like the example everything should work fine. Also, you must have the case loaded. Well, it didn't work after some test. But it recognized the simulation. You need to be sure that you use this syntax   Set hyApp = GetObject(, "HYSYS.Application") Note the , which indicates there is a missing parameter. To be sure, copy and paste.

 

Bobby


Edited by Bobby Strain, 24 February 2014 - 10:07 PM.


#7 Fernando Bórquez

Fernando Bórquez

    Brand New Member

  • Members
  • 8 posts

Posted 25 February 2014 - 06:35 AM

The code I sent works. To use it, you must reference the HYSYS library that is on your machine.  The reference in this workbook is to and older version of the library. Then, if you code like the example everything should work fine. Also, you must have the case loaded. Well, it didn't work after some test. But it recognized the simulation. You need to be sure that you use this syntax   Set hyApp = GetObject(, "HYSYS.Application") Note the , which indicates there is a missing parameter. To be sure, copy and paste.

 

Bobby

 

It was a bug in HYSYS Library, the solution was reinstall all Aspen One from 0.

 

Thank's for your active help.

 

 

Fernando Bórquez


Edited by Fernando Bórquez, 25 February 2014 - 06:42 AM.





Similar Topics