How to use String Vars in a Macro?

Use this forum to post Vensim related questions.
Post Reply
gwr
Senior Member
Posts: 209
Joined: Sun Oct 04, 2009 8:40 pm
Vensim version: DSS

How to use String Vars in a Macro?

Post by gwr »

Dear Support:

I wanted to write a very simple Macro to achieve the following: When reading in a variable as say :HOLD BACKWARD: The variable will not be displayed as a step function. It will only be displayed as a step function when passed to another variable like varDisplayHold = varHold. Unfortunately I am getting an error for not passing literals or String Vars to the GET XLS FUNCTION involved. Here is the code:

Code: Select all

:MACRO: GET XLS DATA HOLD ( filename, tabname, timeRowCol, firstDataCell)
GET XLS DATA HOLD = DataHold ~~|
DataHold = DataRead	~~|
DataRead :HOLD BACKWARD: := GET XLS DATA( filename, tabname, timeRowCol, firstDataCell) ~~|
:END OF MACRO:
How can this be done?

Kind regards,

Guido
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: How to use String Vars in a Macro?

Post by Administrator »

I've just tried your macro and it works for me.

Have you made the relevant parameters that are passed to the macro string variables?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to use String Vars in a Macro?

Post by tomfid »

Macros can only take numeric arguments, I think, though this might work if the arguments you pass are string variables, rather than quoted string literals (i.e. call MYMACRO(x) with x :is: 'bla', rather than MYMACRO('bla')).

But the graph tool normally displays a data var with interpolation, regardless of the interpolation or hold pattern, so this may not be necessary anyway.

Tom
gwr
Senior Member
Posts: 209
Joined: Sun Oct 04, 2009 8:40 pm
Vensim version: DSS

Re: How to use String Vars in a Macro?

Post by gwr »

Tom and Tony(?),

thanks for the responses which unfortunately are not solving my problem: I wanted to hide 'unnecessary' model structure and having to include string vars does do the exact opposite. I really wonder why literals are not accepted as input to a macro - shouldn't that be made possible?

Unfortunately it DOES matter as the graph tool and the strip graph tool both show a held back variable correctly in its step form when it is given as

Code: Select all

var_to_be_shown = var_read_in_as_held_backward
So if macros are no solution please change the way the graph tools display a held back variable: I find it very misleading that they show an interpolated graph for a var that is internally treated as a step var.

Kind regards,

Guido
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: How to use String Vars in a Macro?

Post by Administrator »

thanks for the responses which unfortunately are not solving my problem: I wanted to hide 'unnecessary' model structure and having to include string vars does do the exact opposite.
My preference is to see as much structure as possible. I went through a "painful" model conversion recently (a model built in competitor software to Vensim), and the default in the other app was to hold backward. This was undocumented, and I wasted a lot of time before I figured it out. Hiding things in equation really annoys me (this is just my opinion though). If things really are unnecessary, you can hide them quickly (the only thing I tend to hide from a view is time step).

All of my models that read from Excel have the sheet name, workbook etc as string variables. It makes it easy to change them all in one go rather than have to edit every equation. So having a little extra here can save a lot of time and provide greater flexibility (you could store many scenarios in a workbook and switch between them quickly just by changing a string var).

I'll raise a bug ticket to allow strings into macros, it should be possible (it does work when they are string vars which is strange). And for the graphs (again, I agree, it should show the held backwards data rather than interpolate).
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
gwr
Senior Member
Posts: 209
Joined: Sun Oct 04, 2009 8:40 pm
Vensim version: DSS

Strange things happening...

Post by gwr »

Dear Administrator (Tony? - a name is so much more personal :wink: ),

I agree with making structure explicit and may thus use hiding to 'unclutter' model structure. Nonetheless in this special case the structure is only a work around the false display...

While 'playing' with string vars I noted really strange things in Vensim DSS 6.0.0.1 - maybe you should check this:

1. Starting a new model with a variable in the current view (not entering an equation) and then choosing 'new view' from the menu will cause the view counter to increase still showing the variable from the first view. What is even stranger is that I can not enter an equation using the equation sketch tool. The variable simply cannot be selected with the equation tool.

2. I tried to enter string variables as filename and tabname for a data variable. Here I chose to enter the filename in the text editor:

Code: Select all

filname :IS: 'myFile.xlsx' ~~|

While entering the variable tabname as a string variable in the sketch editor. Now, entering a new variable data in the sketch editor and then using the equation editor to make it a data equation with GET XLS DATA the equation editor will not show the string variables as an input option (even when chosing 'ALL' in the drop down menu) in the variable windows unless one has previously connected them using arrows. I think that should be changed and string vars should be added to the dropdown menu for the type of variable to be shown.

Kind regards,

Guido
gwr
Senior Member
Posts: 209
Joined: Sun Oct 04, 2009 8:40 pm
Vensim version: DSS

Re: How to use String Vars in a Macro?

Post by gwr »

A short update to my last post:

The problem described under (1.) has been resolved. For some reason the unconscious parts of me must have marked "Use Template View" - a feature I have never used so far...

So there just remains the issue of bringing String Vars into the equation editor if they have not been linked with arrows yet.

Guido
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: How to use String Vars in a Macro?

Post by tomfid »

We'll put #2 on the bug list - should be an easy fix.

For filenames going into GET XLS calls, it's probably easier to mange them with the '?myfile' alias, so that you can then manage it using the Model>Settings>XLS Files tab. For other things, like tab or cell names, strings are the only option.
gwr
Senior Member
Posts: 209
Joined: Sun Oct 04, 2009 8:40 pm
Vensim version: DSS

Re: How to use String Vars in a Macro?

Post by gwr »

Tom,

great to hear that and I am looking forward to see the :Hold Backward: and :Look Forward: data variables being displayed accurately.

While the mistery of variables not disappearing in a new view has been resolved (template view) I do struggle to find any documentation on those items. In the Vensim Reference manual the View-menu is shown without these entries:

http://www.vensim.com/documentation/index.html

Is there any documentation about how Use Template and Template View can be put to best possible use?

Guido
Post Reply