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

[EnergyPlus_Support] Re: Running simulation using VB



THANKS SOOOOOOOO MUCH, it works!

--- In EnergyPlus_Support@xxxxxxxxxxxxxxx, Edwin Lee <leeed2001@...> wrote:
>
> An improved method over the base vba shell command, is to use an API call
> and use shellexecute.  This command is more robust, and allows you to be
> more specific when passing arguments and such.  This snip of code works
> great for me.  The command prompt is only open briefly because the example
> file runs quickly, but it does run fine:
> 'Setup a call to the external shell execute function
> Const SW_SHOW = 1
> Public Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA"
> _
>   (ByVal hwnd As Long, _
>    ByVal lpOperation As String, _
>    ByVal lpFile As String, _
>    ByVal lpParameters As String, _
>    ByVal lpDirectory As String, _
>    ByVal nShowCmd As Long) As Long
> 
> 'Simple subroutine to run eplus batch file.  Pass in three arguments: Path
> to batch file, Input File Name (if it is in the example files folder), and
> the working directory (directory containing batch file)
> Sub RunYourProgram()
>   Dim RetVal As Long
>   On Error Resume Next
>   RetVal = ShellExecute(0, "open", "C:\EnergyPlusV3-0-0\RunEPlus.bat",
> "PlantLoadProfile", "C:\EnergyPlusV3-0-0\", SW_SHOW)
> End Sub
> 
> If you are running files that aren't in the example files folder, you may
> run into some other issues, but that should be a start...
> 
> Edwin
> 
> On Tue, Mar 17, 2009 at 6:16 PM, gadolio2002 <gadolio2002@...> wrote:
> 
> >   I tried the first option but it keeps telling me that it can't find the
> > Energy+.idd file although its in the same directory.
> > Here is the code,
> >
> > Private Sub CommandButton1_Click()
> > Dim RetVal
> > RetVal = Shell("C:\EnergyPlusV3-0-0\RunEplus.bat plant LasVegas", 4)
> > End Sub
> >
> > Upon execution, a command window appears instantaneously then disappears,
> > and no results are stored.
> >
> > Appreciate your help.
> >
> >
> > --- In EnergyPlus_Support@xxxxxxxxxxxxxxx<EnergyPlus_Support%40yahoogroups.com>,
> > Edwin Lee <leeed2001@> wrote:
> > >
> > > I guess there's a couple options.
> > > 1) Modify your macro to run the EnergyPlus.exe directly and avoid the
> > batch
> > > file. This would require setting up the input file and renaming it to
> > > in.idf, as well as copying your weather file to in.epw. Then you would
> > > post-process as necessary.
> > >
> > > 2) When you use the shell command, you have to be careful with your
> > quotes
> > > if you are passing paths with directories and spaces. I have run batch
> > > files and such from VBA in the past, and I remember having some issues
> > with
> > > the shell function, but that stuff's long gone with a reformat. If your
> > > issue is directly related to the shell function, you may have better luck
> > > hitting a vba forum. If you'd like to post a brief snip of your vba
> > routine
> > > (only the relevant variables and calls), I'll have a look at it.
> > >
> > > Edwin
> > >
> > > On Tue, Mar 17, 2009 at 5:51 PM, gadolio2002 <gadolio2002@> wrote:
> > >
> > > > Thanks for the response Edwin. I've already tried to follow the
> > > > documentation, but it seems that when I execute the command to run the
> > > > simulation using the Shell function, it doesn't pass the input file
> > name to
> > > > E+ batch file (the simulation initiates but stops soon sfter because no
> > > > input file was specified)?
> > > >
> > > > Thanks Again.
> > > >
> > > >
> > > > --- In EnergyPlus_Support@xxxxxxxxxxxxxxx<EnergyPlus_Support%40yahoogroups.com>
> > <EnergyPlus_Support%40yahoogroups.com>,
> > > > Edwin Lee <leeed2001@> wrote:
> > > > >
> > > > > To run E+ from a VBA macro, you'll probably just be starting an
> > > > executable
> > > > > through the shell. This can be found all over the place with google:
> > > > >
> > > >
> > http://www.computing.net/answers/programming/vba-shell-function/2677.html
> > > > >
> > > > > for one.
> > > > >
> > > > > There is information in the AuxillaryPrograms.pdf documentation that
> > > > comes
> > > > > with E+ about how to run E+ directly, without a front-end. Just
> > search on
> > > > > 'Running EnergyPlus by Hand'.
> > > > >
> > > > > Good luck...
> > > > > Edwin
> > > > >
> > > > > On Tue, Mar 17, 2009 at 5:03 PM, gadolio2002 <gadolio2002@> wrote:
> > > > >
> > > > > > Hi All,
> > > > > >
> > > > > > Can someone guide me through how to run an EnergyPlus Simulation
> > using
> > > > > > Microsoft Visual Basic Macro (from Excel)?
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> >
> >  
> >
>




------------------------------------

The primary EnergyPlus web site is found at:
http://www.energyplus.gov

The group web site is:
http://groups.yahoo.com/group/EnergyPlus_Support/

Attachments are not allowed -- please post any files to the appropriate folder in the Files area of the Support Web Site.

EnergyPlus Documentation is searchable.  Open EPlusMainMenu.pdf under the Documentation link and press the "search" button.
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/EnergyPlus_Support/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/EnergyPlus_Support/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:EnergyPlus_Support-digest@xxxxxxxxxxxxxxx 
    mailto:EnergyPlus_Support-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    EnergyPlus_Support-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/