Welcome to WEAP's Website WEAP
WEAP is an initiative of the Stockholm Environment Institute.


About WEAP

Home
Why WEAP?
Features
What's New?
Sample Screens
Demonstration
Publications
History and Credits

Using WEAP
Download
Licensing
User Guide
Tutorial
Videos (YouTube)

User Forum
Discussions
Members List
Edit Profile

Additional Support
Training
University Courses
Collaboration

About Us
SEI-US Water Resources Program
Please Contact Us

LEAP
Interested in Energy?
Read about LEAP: SEI's software for energy planning.

Link WEAP and LEAP for combined Water-Energy planning.
Watch a video demo!
   

User Forum

All Topics | Topic "Scripting"
Log in to post new messages or reply to existing messages.
 
Author Message
Mr. Julien Verdonck

Subject: Scripting   
Posted: 5/2/2011 Viewed: 33280 times
Dear colleagues,

I am trying to run a VB script with WEAP, at the end of the calculations.
The objective of the script is to write various results (flow data for instance) in an external Excel file.

The script works very well if I ask to copy 100 values to my Excel sheet. But as soon as I ask to copy more values, it stops during the execution and an error message tells me that there is a "Unknown runtime error".

I don't think that this is a problem of the "Sript Timeout" factor because I tried to change it without success.

Does anybody also face similar problem and does anybody know how to solve it?

Thank you very much for your attention. I can send more details on demand.
Best regards,

Julien VERDONCK, currently in Chad.
Mr. Jack Sieber

Subject: Re: Scripting   
Posted: 5/2/2011 Viewed: 33272 times
Julien,

Can you please send me a copy of the WEAP area so that I can try to reproduce the error?

Jack
Mr. Huzefa Haji

Subject: Re: Scripting   
Posted: 5/9/2011 Viewed: 33224 times
Hi Julien,
I would also like to export stream flow results to an excel file. Unfortunately I have zero background in VB and am in the process of learning how to use it. Would it be possible to have a copy of your script? that would greatly assist me in understanding how it works.

Many thanks.

Huzefa
Mr. Julien Verdonck

Subject: Re: Scripting   
Posted: 5/25/2011 Viewed: 33139 times
Dear Jack,

Thank you very much for your prompt answer and sorry for my late reply. Internet was very bad in Chad.

The script was in fact ok and my mistake was to touch the excel file while WEAP was filling it. Indeed, touching the Excel file while WEAP is working on it immediately stops the script.

Now I have added to the script a message box which tells me when the run is completed.

Best regards,

Julien
Mr. Julien Verdonck

Subject: Re: Scripting   
Posted: 5/25/2011 Viewed: 33135 times
Dear Huzefa,

Please find below an extract of my script.
It will open the file "C:\XXX\Excel_file.xls" and the sheet "Name_of_the_sheet" and write in a column the monthly streamflows of the WEAP branch (to be changed according to your model) "Supply and Resources\River\Chari\Reaches\Below Return Flow Node 28".
The time step I use is the monthly time step.

Cheers,

Julien
-------------------------------------

Dim objExcel
Call openxls("C:\XXX\Excel_file.xls")

Function OpenXls(str)
Set objExcel=CreateObject("Excel.Application")
objExcel.Visible=true
objExcel.Workbooks.Open str

dim my_year
dim i
i=1

set my_sheet=objExcel.worksheets("Name_of_the_sheet")
for my_year=1950 to 2000
for my_month=1 to 12
set my_cell=my_sheet.cells(i,7)
my_cell.value=WEAP.Branch("Supply and Resources\River\Chari\Reaches\Below Return Flow Node 28").Variables("Streamflow").Value(my_year,my_month)
i=i+1
next
next
End Function
Mr. Huzefa Haji

Subject: Re: Scripting   
Posted: 5/26/2011 Viewed: 33125 times
Dear Julien,
Many thanks for the script!

Regards,
Huzefa
Topic "Scripting"