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 User Variable For A Beginner

hysys code vba user variable program coding macro automation

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

#1 noh6pka

noh6pka

    Brand New Member

  • Members
  • 3 posts

Posted 20 January 2016 - 02:25 AM

Hello,

 

This is my first time to write up my question in Cheresources.com. I am a beginner using user variable in HYSYS.

 

Simply, I want to make one of stream temperature popped up in msgbox, but keep failed. The below is my coding. Can you help find which one should be added or changed?

 

 

Sub PostExecute()

 

Dim hyCase as Object

Dim hystream as processstream

Dim T as double

 

set hystream = hycase.Flowsheet.Materialstreams.index("stream name")

T= hystream.Temperaturevalue

MsgBox "temperature" & T

 

End Sub

 

 

I appreciate your attention.



#2 Lucian Gomoescu

Lucian Gomoescu

    Veteran Member

  • Members
  • 44 posts

Posted 21 January 2016 - 04:01 PM

Hello,

I've created a file called "UserVariable.hsc" and created a "CodeOnly" user variable from Flowsheet>Flowsheet User Variables, which i named "test".

 

The only code that i wrote is below.
 

Sub PostSolve()

Dim path As String
Dim hyCase As Object
Dim hyStream As Object
Dim T As Double

path="D:\Miscellaneous\Cheresources\2016_01_21\UserVariable.hsc" 'change this with your path

Set hyCase =GetObject(path,"HYSYS.SimulationCase")
Set hyStream=hyCase.Flowsheet.Streams.Item("Stream 1")

T= hyStream.TemperatureValue

MsgBox "Stream 1 temperature is " & hyStream.Temperature.GetValue("C") & "°C"

End Sub

 

Then i maked sure that it is activated (checked box @ Flowsheet>Flowsheet User Variables).
It worked: everytime the solver finishes execution, the message box pops up.

Regards,
Lucian



#3 noh6pka

noh6pka

    Brand New Member

  • Members
  • 3 posts

Posted 24 January 2016 - 03:29 AM

Hello Sir,

 

It is really working. Deeply appreciate your help.

 

Just one more question. Actually what I wanted to do at the beginning is to see component fraction in the MSGBOX. I tried to do it, but it is more complicated than temperature because it is array value.

 

Could you advise me once again to run component fraction in the MSGBOX?

 

Regards,



#4 noh6pka

noh6pka

    Brand New Member

  • Members
  • 3 posts

Posted 27 January 2016 - 06:29 AM

I find a way. The below is my solution.

 

Sub PostExecute()

Dim path As String

Dim hycase As object

Dim hyflowsheet As Processstream

Dim hycomponents As Components

Dim hycompfrac As Variant

 

path="D:\users\noh6pka\Desktop\name.hsc"

Set hycase=Getobject(path, "Hysys.simulationCase")

Set hyflowsheet=hycase.Flowsheet

Set hystream=hyflowsheet.MaterialStreams.Item("stream name")

Set hycomponents=hyflowsheet.FluidPackage.Components

hycompfrac=hystream.ComponentMolarFractionValue

 

For j=0 To UBound(hycompfrac)

Msgbox "Component: " & hycomponents.Item(j) & ", Mol Fraction= " & hycompfrac(j)

Next j

End Sub

 

For anyone's information.


Edited by noh6pka, 27 January 2016 - 06:30 AM.





Similar Topics