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.
referring to a field indirectly
-
- Posts: 1796
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: referring to a field indirectly
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.