Page 1 of 1

referring to a field indirectly

Posted: June 9th, 2020, 4:52 pm
by AriSilva
Is it possible to change the contents of a variable without knowing its name?
For example I want to change the contents of a variable named SEX.
So I can write
SEX = 2;

Can I write something like:
string varname = "sex";
setContents(varname, 2);

which would do the same as the direct assigning.
Why would I need that?
I have a need to edit some variables according to some user commands. So I thought about having an excel file with three columns:
1. Id
2. variable
3. new_value
Reading this file and for each line in the file apply the change accordingly.

Re: referring to a field indirectly

Posted: June 9th, 2020, 5:23 pm
by Gregory Martin
You can use setvalue: https://www.csprousers.org/help/CSPro/s ... ction.html
setvalue("SEX", 2);
I've used this to do recoding from an Excel file, which sounds like your exact use case.

Re: referring to a field indirectly

Posted: June 10th, 2020, 10:02 am
by AriSilva
Great!
That is exactly what I have in mind!