Results 1 to 3 of 3

Thread: Access (read & write) My.Settings depending on a variable?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2023
    Posts
    54

    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 ?
    Name:  Snap2.jpg
Views: 273
Size:  17.4 KB
    Last edited by marsias; Sep 10th, 2024 at 08:56 AM.

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,439

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,686

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width