[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: Control Trnsys by command line



Dear TRNSYS users,
thanks to all of you who answered. It seems like this was a beginners
question... 

Especially concerning your question, Timo, I have added a code snippet, that
checks wether Trnsys is running or has finished. It works with some API
functions and can be used with VBA or VB (I'm using XP and Win2K, but it
should work with other versions, too).  
Regards,

Jochen

'////////////////////////////////////////////////////////////////////

Option Explicit

Private Declare Function CloseHandle Lib "kernel32" _
                        (ByVal hObject As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" _
                        (ByVal dwDesiredAccess As Long, _
                         ByVal bInheritHandle As Long, _
                         ByVal dwProcessId As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
                        (ByVal hProcess As Long, _
                         lpExitCode As Long) As Long

Const STILL_ACTIVE = &H103
Const PROCESS_ALL_ACCESS = &H1F0FFF

Private lngTrnsysHandle As Long

Private Function TrnsysActive() As Boolean
' Get status of last started trnsys task
   Dim Proc As Long, OutOf As Long
   Proc = OpenProcess(PROCESS_ALL_ACCESS, False, lngTrnsysHandle)
   Call GetExitCodeProcess(Proc, OutOf)
   Call CloseHandle(Proc)
   TrnsysActive = IIf(OutOf = STILL_ACTIVE, True, False)
End Function

Private Sub CheckIfFinished()
'   looping procedure until Trnsys has finished
    If TrnsysActive Then
     ' Wait one second, then check it again...
      Application.OnTime Now + TimeValue("00:00:01"), "CheckIfFinished"
    Else
      MsgBox "Now I can do postprocessing!"
     
     ' ...
     ' Call MyPostproc
     '...
    
    End If
End Sub
 

Sub RunTrnsys()
   ' Get handle of trnsys task
    lngTrnsysHandle = Shell("C:/trnsys15/trnsys XYZ.dck /n")
   
   ' Tell VBA to check for finishing in a time intervall of one second
   ' (In VB you can use Timer statements)
   Application.OnTime Now + TimeValue("00:00:01"), "CheckIfFinished"

End Sub 

> -----Ursprüngliche Nachricht-----
> Von: owner-trnsys@xxxxxxxxxxxxxxxxxxx 
> [mailto:owner-trnsys@xxxxxxxxxxxxxxxxxxx] Im Auftrag von Jochen Wriske
> Gesendet: Mittwoch, 16. Juni 2004 15:09
> An: trnsys@xxxxxxxxxxxxxxxxxxx
> Betreff: Control Trnsys by command line
> 
> Dear TRNSYS users,
>  
> is there a way to avoid the display of the 'simulation 
> completed' dialog after trnsys has finished simulating? I 
> would like to do multiple simulations in a kind of batch mode 
> in VB by executing somthing like
> 
> Shell ("C:/trnsys15/trnsys fileXYZ.dck").
> 
> This works fine, but I have to confirm the mentioned dialog 
> before I'm able to work with the result files. That is quite tideous.
> 
> Of course there are some system near solutions like getting 
> handle of the dialog window and emulating the OK click, but 
> my hope is that there is a switch somewhere in a 
> configuration file that tells trnsys to finish simulating 
> silently. I could not find something usefull in the manual 
> concerning this problem, but maybe someone has a good idea?
> 
> Thanks and regards,
> 
> Jochen
> 
>