Results 1 to 9 of 9

Thread: [RESOLVED] [2008] understanding my.settings

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    170

    Resolved [RESOLVED] [2008] understanding my.settings

    I'm in the process of upgrading from vb6 to .net and still a little new to it. I've been reading up everywhere i can find on my.settings. Previously I had been using an .ini file. At run time I was able to open that file and modify it if necessary:

    Code:
    Dim theiniid As Double
    ChDir App.Path
    If Dir("myinifile.ini") <> "" Then
        theiniid = Shell("Notepad myinifile.ini", vbMaximizedFocus)
    End If
    The first thing I've been trying to resolve is that the My.settings config file gets stored several levels deep into the users documents dir. Whats the VB code to access that path since its local per user per OS?

    Secondly since the style type is changing from *.ini to *.xml ive been considering creating a form to show these items instead. XML isn't as clean to look at, a form with a listbox would be much easier on the eyes.

    Some code i've found to generate this:

    Code:
    For Each item As System.Configuration.SettingsProperty In My.Settings.Properties
        listbox1.items.additem(item.name)
    Next
    The problem with this batch of code is that item.value doesnt exist, is there a way to access that via this method?

    Another thing I've noticed is that during the inital stage of the code I declare

    Code:
    mainform.hide
    formnumber2.show
    irrigardless the primary form pops up anyways. Anyone know how to stop that?
    Thanks
    Last edited by Xilbus; Mar 26th, 2008 at 11:48 AM.
    You're the King? Well I didn't vote for you...

  2. #2
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [2008] understanding my.settings

    In solution explorer right click on My Project, click on the Settings tab. This is where you enter the information that you want to persist. Once you have done that when you enter My.Settings. intellisense will display all the settings that you have created.
    For instance if you had created a setting Named AppPath and given a string type and the path intellisense would show AppPath
    Once you have done that go the Application tab and check Save My.Settings on shut down.

    Hope this helps
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    170

    Re: [2008] understanding my.settings

    I've already gotten that far. What i want to do now is take, for example, all of the strings that are being maintained there and populate them into a listbox or bring up the configuration file that keeps them for editing at the run time.
    You're the King? Well I didn't vote for you...

  4. #4
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [2008] understanding my.settings

    How many do you have?
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    170

    Re: [2008] understanding my.settings

    20-30
    You're the King? Well I didn't vote for you...

  6. #6
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [2008] understanding my.settings

    Oh I see your problem now.
    The file is in the project directory and is named app.config. Since I am not familiar with XML I am affraid this is as far as I can help you. I think that you will need to recurse through the nodes to get the info.
    If you have a common name like appPath1, appPath2, appPath3, appPath4 and so on you could use a for loop using My.Settings.AppPath & i
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  7. #7
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [2008] understanding my.settings

    Or use the index

    Code:
    My.Settings.Item(i)
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    170

    Re: [2008] understanding my.settings

    Code:
            
    For Each item As System.Configuration.SettingsProperty In My.Settings.Properties
       If My.Settings.Item(item.Name) IsNot Nothing Then
          ListBox1.Items.Add(My.Settings.Item(item.Name))
       End If
    Next item
    yep that did it, thanks
    You're the King? Well I didn't vote for you...

  9. #9
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [RESOLVED] [2008] understanding my.settings

    Good for you. If that solves your problem you may want to mark this thread as resolved.
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

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