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
vensim_get_data into Excel
-
- Super Administrator
- Posts: 4592
- Joined: Wed Mar 05, 2003 3:10 am
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)
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)
-
- Super Administrator
- Posts: 4592
- Joined: Wed Mar 05, 2003 3:10 am
>> 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.
>> 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.
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
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