-
Sep 10th, 2024, 08:53 AM
#1
Thread Starter
Member
Access (read & write) My.Settings depending on a variable?
Hello.
In My.settings i have 3 collections s1,s2,s3 which each has Boolean data.(true,false,false etc)
In Program, i access each ,with my.settings.s1(i) with no Problem.
But i wont to choice in app which line to take.
A attempt to make a variable let say for example a=s3 and then my.settings.a(i), i have a error "a" ist not member of my.settings
How to do that ?
Last edited by marsias; Sep 10th, 2024 at 08:56 AM.
-
Sep 10th, 2024, 03:01 PM
#2
Re: Access (read & write) My.Settings depending on a variable?
-
Sep 10th, 2024, 10:04 PM
#3
Re: Access (read & write) My.Settings depending on a variable?
If you declare a variable 'a' in a form or wherever else then it's not a member of My.Settings, is it? No, so writing My.Settings.a makes no sense. You need to use that variable the same way you would any other variable, e.g.
Code:
Dim settingsCollection As Specialized.StringCollection
Select Case someVariable
Case 1
settingsCollection = My.Settings.s1
Case 2
settingsCollection = My.Settings.s2
Case 3
settingsCollection = My.Settings.s3
End Select
settingsCollection(i) = someValue
BTW, do better with your naming conventions. 's1', etc, are terrible names for anything. The name should tell anyone who doesn't already know what it is, what it is. Trust me, if you keep using names like that, it won't be long before you pick up a project you haven't touched for a while and have no idea what any of your variables are actually for. Maybe these are just examples for a test/demo, in which case it's not a big deal, but if you really are using such names, as many people do, I suggest that you address that immediately, for your own benefit as well as that of anyone else who reads your code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|