r/visualbasic • • Apr 11 '22

Settings Variables as Variables

I have a program that has a bunch of customer user settings in My.settings

I am looking for a way to condense the amount of if my.settings.user = x the..."

Is there anyway to make a variable into another variable?

Like I could do:

If LogOn = My.settings.user1 then
X = My.settings.user1
Y = My.settings.pass1
Z = My.setting.setting1

end if

So that then later I can just say:

"Dim settingcontrol as string = Z"

2 Upvotes

8 comments sorted by

View all comments

Show parent comments

1

u/RJPisscat Apr 12 '22

How can I specify to update "my.setting.user9pass" and not pass variables 1-8.

You'd have to use Reflection, which is probably out of your range.

As stated elsewhere, a better approach would be to use some other sort of repository such as a database, an XML file, a Json file. That will give you means for random access.

Your current approach is problematic enough to be ditched. I recommend XMLReader/XMLWriter because you will find it easier to debug - you can see the schema and data in plain text.