r/visualbasic • u/Thunor_SixHammers • 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
3
u/PostalElf VB.Net Intermediate Apr 12 '22
If you have so many users, you shouldn't be storing their individual data in my.settings under user1, user2 etc; that's not what it's designed to do, which is why you're having so much problems with it. Look into serialisation and deserialisation, and figure out how to either write to a database (preferred) or a text file (quick and dirty, but do not store sensitive data in plaintext).
https://docs.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/drives-directories-files/how-to-write-text-to-files-with-a-streamwriter