vensim_get_data into Excel

Use this forum to post Vensim related questions.
Post Reply
jv104
Junior Member
Posts: 9
Joined: Thu Mar 25, 2010 10:53 am

vensim_get_data into Excel

Post by jv104 »

Hi,

I have a table in VENSIM that relates to 25 vals

Private Sub ResultGet()

result = vensim_get_data("base", "LR Susceptible 1[age1,female]", "TIME", vval, tval, 1)
Worksheets("sheet1").Cells(6, 16) = result
Worksheets("sheet1").Cells(7, 16) = vval
Worksheets("sheet1").Cells(8, 16) = tval

End Sub

How would I get the 25 pairs of results into Excel. Currently if I change the maxn to 25 Excel crashes.

Any suggestions or points of reference in the manual would be great.

Thanks

Joe
Administrator
Super Administrator
Posts: 4592
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

The best way is to do something like

MaxPointsAvailable = vensim_get_data("base", "LR Susceptible 1[age1,female]", "TIME", vval, tval, 0)

redim vval(MaxPointsAvailable)
redim tval(MaxPointsAvailable)

result = vensim_get_data("base", "LR Susceptible 1[age1,female]", "TIME", vval, tval, MaxPointsAvailable)
jv104
Junior Member
Posts: 9
Joined: Thu Mar 25, 2010 10:53 am

Post by jv104 »

Hi

Thanks for the quick response. I have tried to implement the code above but I get a compile error stating that I am making Invalid ReDim.

Do I need to define vval and tval, as I haven't currently done this?

Many thanks again

Joe
Administrator
Super Administrator
Posts: 4592
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

>> Thanks for the quick response. I have tried to implement the code
>> above but I get a compile error stating that I am making Invalid ReDim.
You will need to check the exact syntax (it's been a while since I used VB).

>> Do I need to define vval and tval, as I haven't currently done this?

Dim tval(500) As Single
Dim rval(500) As Single
dim MaxPointsAvailable as long

MaxPointsAvailable = vensim_get_data("base", "LR Susceptible 1[age1,female]", "TIME", vval, tval, 0)

'check for an error
if ( MaxPointsAvailable <= 0 )
'ERROR CHECK
endif

redim vval(MaxPointsAvailable)
redim tval(MaxPointsAvailable)

result = vensim_get_data("base", "LR Susceptible 1[age1,female]", "TIME", vval, tval, MaxPointsAvailable)


There is an example that ships with Vensim, look into the "C:\Program Files\Vensim\dll\VBASIC40" directory, this has the calls to do many things with the DLL.

Tony.
jv104
Junior Member
Posts: 9
Joined: Thu Mar 25, 2010 10:53 am

Post by jv104 »

Thanks Tony,

I am trying to use the code in Excel and I now get the compile error: ByRed argument type mismatch.

What I would like to do is extract the data from a VENSIM table and place it in Excel. The code I am using is trying to get the information from a single variable in the model. The code that I am using is:

Private Sub ResultGet()

Dim tvals(500) As Single
Dim vvals(500) As Single
Dim MaxPointsAvailable As Long

MaxPointsAvailable = vensim_get_data("base", "LR Susceptible 1[age1,female]", "TIME", vvals, tvals, 0)
ReDim vvals(MaxPointsAvailable)
ReDim tvals(MaxPointsAvailable)

result = vensim_get_data("base", "LR Susceptible 1[age1,female]", "TIME", vvals, tvals, MaxPointsAvailable)

End Sub

Is this the best way to do this in Excel. Many of the other commands I have used are VBA based and are working - I just can't get the output of results to work.

For reference other code

Private Sub OpenVENSIMNormal()

result = vensim_command("SPECIAL>LOADMODEL|E:\Joe's Documents\University\PhD 2006-10\MODELS\System Dynamics\Viana 1.vpm")

End Sub

Private Sub StartSimulation()

result = vensim_command("SIMULATE>RUNNAME|base")
If result = 0 Then Exit Sub

result = vensim_command("MENU>RUN1")

End Sub

Joe
jv104
Junior Member
Posts: 9
Joined: Thu Mar 25, 2010 10:53 am

Post by jv104 »

Hi Tony,

Don't worry I have found the VENDLL.XLS example and I have figured it out. Many thanks again for your advice though.

C:\Program Files\Vensim\dll\EXCEL7

Joe
Post Reply