Subscripted strings/String arrays

Use this forum to post Vensim related questions.
Post Reply
NickB
Junior Member
Posts: 5
Joined: Mon Dec 03, 2007 10:39 am

Subscripted strings/String arrays

Post by NickB »

Hi all,
I'm having some trouble defining subscripted strings. I want to have a model which will allow me to automatically update the subscript element names through Excel.

To this end, I have changed my existing model to have generic subscript names (first, second etc), and now wish to declare a name variable which will store the strings for each of the elements. This will allow me to use a different input sheet and have the names in the model update automatically.

However I have been unable to define this array, either as a constant type or as a string type, I always receive the 'Expecting Operator' error. Does anyone have any suggestions? I am using Vensim DSS 5.3.

Many thanks
Nick
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Does the attached work ok for you?

Tony.
Attachments
forum.zip
(896 Bytes) Downloaded 314 times
NickB
Junior Member
Posts: 5
Joined: Mon Dec 03, 2007 10:39 am

Post by NickB »

Hi Tony,
Yes, that works fine, however what I'm trying to do is specify an array of strings, e.g:
sub: first, second, third
some string variable[sub] :IS: 'Test1', 'Test2', 'Test3'

There's one thing I found in the Vensim help, under 'String Variables in Graphs and Tables', where the following is listed:

pname[p1] :IS: 'Super Sudser' ~~|
pname[p2] :IS: 'Brass Polish' ~~|

However, I can't find any reference to how the pname array is originally declared. I'm not sure if this is possible, but it would be useful to know that it is impossible so I can look for another work around.
Hope this has made some sense.
Nick
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

That is the declaration of the pname array - you need 1 equation for each entry.
NickB
Junior Member
Posts: 5
Joined: Mon Dec 03, 2007 10:39 am

Post by NickB »

Thanks, I had already tried that, but it was creating a new subscript for each of the different elements. I moved the individual declarations to after the subscript declaration and it now appears to be behaving properly.
Many Thanks
Nick
NickB
Junior Member
Posts: 5
Joined: Mon Dec 03, 2007 10:39 am

Post by NickB »

Another small problem I've not been having too much luck with. I have the name[sub] variable working properly, but can't import the strings from Excel. GET XLS DATA and GET XLS CONSTANTS both expect to read numerical values. Is there any way around this?
Many thanks in advance (even if it's just saying it's impossible)
Nick
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

I believe you can only read numerical cells. Bob will confirm later though. You could write a macro to dump the string names into a .CIN file.

Tony.
NickB
Junior Member
Posts: 5
Joined: Mon Dec 03, 2007 10:39 am

Post by NickB »

Thanks Tony, I had thought of that, but I'm trying to have the model working two ways:

1. From within Excel, which works, since there's no need to change the internal model names from 'first' etc., since all the output goes into the same spreadsheet so you can get the names without having them output from the model.

2. From within Vensim. Currently it can take in the values for the parameters, but the graphs created still have 'first' etc. as the legend names, and I'd like those to come from the spreadsheet instead.

So a .cin file would work, but would have to be generated externally to Vensim. I might use this if there isn't any way to pull the strings directly from Excel, but would turn running the model into a two step process.
Thanks
Nick
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

You can't use the GET XLS... functions to read in values for string variables but they can be set in .cin files

stringval :IS: 'value'

you might need to leave off the '' in older Vensim versions.
Post Reply