|
-
May 12th, 2009, 08:17 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Save and load variable values from/to file
Hello.
I've been literally googling for an hour now trying to find how to save variable settings to a file. Now i turn to you guys on this forum for help.
I'm writing an application and I'm using alot of changeable variables. I want to be able to save these to a file so they can be loaded at application startup. I don't feel like using the regestry since I hate to write unimportant things to the registry.
I remembered that I found a good example with simple code of how to do this with xml, but I can't seem to find the example now.
Could someone please explain to me how to do this in an easy and smart way.
Thank you
-
May 12th, 2009, 08:22 AM
#2
Re: Save and load variable values from/to file
You certainly shouldn't be using the Registry because the .NET Framework introduced application config files specifically so you wouldn't. VB 2008 introduced My.Settings to make it even easier. Open the project properties and select the Settings page. Now click the link at the top and read on for the solution to your problem.
-
May 12th, 2009, 09:42 AM
#3
Thread Starter
Addicted Member
Re: Save and load variable values from/to file
Last edited by n00b scripter; May 12th, 2009 at 11:58 AM.
-
May 12th, 2009, 12:01 PM
#4
Thread Starter
Addicted Member
Re: Save and load variable values from/to file
Ok so I got it working alright.
BUT, something is messed up. The values does change and is saved if I restart the application.
The <applicationName>.exe.config stays the same. It doesn't change. Where the hell are the settings stored? :-o What's happened? :-o
And yes I have built the application so I don't run it in debugger.
I'm using this code to modify:
Code:
With My.Settings
.Test = textbox1.text
End With
-
May 12th, 2009, 01:01 PM
#5
Re: Save and load variable values from/to file
 Originally Posted by jmcilhinney
vb 2008 introduced my.settings to make it even easier.
vb 2005..?
-
May 12th, 2009, 03:21 PM
#6
Re: Save and load variable values from/to file
@noob scripter
I think it's just My.Settings.Test = TextBox1.Text. Not sure what your with statement is for.
-
May 12th, 2009, 04:33 PM
#7
Thread Starter
Addicted Member
Re: Save and load variable values from/to file
Well I believe that 'with' is a way to cut down on the codewriting. I guess there something more it but for example:
If you have long variablenames and would end up with:
VB Code:
UserHandler.GetUser.First.User.FirstName="Stefan" UserHandler.GetUser.First.User.LastName="Karlsson" UserHandler.GetUser.First.User.Age="39" UserHandler.GetUser.First.User.Sex="Male" UserHandler.GetUser.First.User.Occupation="Programmer" UserHandler.GetUser.First.User.UserID="0"
then I would use WITH to make it more readable:
VB Code:
With UserHandler.GetUser.First.User .FirstName="Stefan" .LastName="Karlsson" .Age="39" .Sex="Male" .Occupation="Programmer" .UserID="0" end with
And in this application I do have a lot of lines
-
May 12th, 2009, 06:52 PM
#8
Re: Save and load variable values from/to file
 Originally Posted by n00b scripter
Ok so I got it working alright.
BUT, something is messed up. The values does change and is saved if I restart the application.
The <applicationName>.exe.config stays the same. It doesn't change. Where the hell are the settings stored? :-o What's happened? :-o
And yes I have built the application so I don't run it in debugger.
I'm using this code to modify:
Code:
With My.Settings
.Test = textbox1.text
End With
The application config file contains the initial values for all your settings. Any settings you create with User scope will then be copied into a user config file stored under each user's Documents and Settings folder. When you edit settings at run time, that's where the changes are made. This also means that there is a different set of settings values for each Windows user who uses your application.
-
May 13th, 2009, 04:02 AM
#9
Thread Starter
Addicted Member
Re: Save and load variable values from/to file
 Originally Posted by jmcilhinney
The application config file contains the initial values for all your settings. Any settings you create with User scope will then be copied into a user config file stored under each user's Documents and Settings folder. When you edit settings at run time, that's where the changes are made. This also means that there is a different set of settings values for each Windows user who uses your application.
Aah, I see. Okey I found where it's stored. I'm using the VS on my school computer and the values are store in a folder named as the companys name which is my schools. This folder is automatically created and named the same on every computer. Is there anyway to change this in the application? I don't really feel that it would be good if a publish it on the internet and the folder is called as that companys name on some unknown users computer.
-
May 13th, 2009, 04:22 AM
#10
Re: Save and load variable values from/to file
If you want a different company name then change the company name. Click the assembly Information button on the Application tab of the project properties.
-
May 15th, 2009, 07:58 AM
#11
Thread Starter
Addicted Member
Re: Save and load variable values from/to file
 Originally Posted by jmcilhinney
If you want a different company name then change the company name. Click the assembly Information button on the Application tab of the project properties.
Ok thank you I think I got it all working now. Thx for all the great help
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
|