|
-
Mar 26th, 2008, 11:27 AM
#1
Thread Starter
Addicted Member
[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...
-
Mar 26th, 2008, 01:28 PM
#2
Fanatic Member
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?
-
Mar 26th, 2008, 02:01 PM
#3
Thread Starter
Addicted Member
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...
-
Mar 26th, 2008, 02:15 PM
#4
Fanatic Member
Re: [2008] understanding my.settings
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?
-
Mar 26th, 2008, 02:25 PM
#5
Thread Starter
Addicted Member
Re: [2008] understanding my.settings
You're the King? Well I didn't vote for you...
-
Mar 26th, 2008, 02:36 PM
#6
Fanatic Member
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?
-
Mar 26th, 2008, 02:38 PM
#7
Fanatic Member
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?
-
Mar 26th, 2008, 03:21 PM
#8
Thread Starter
Addicted Member
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...
-
Mar 26th, 2008, 03:23 PM
#9
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|