views:

429

answers:

7

Hi, I'm trying to figure out how to do this as I'm not sure what's the proper way of doing this.

I've got several strings that I want to store/save permanently, even after the application is closed. How should I proceed? Do I read or write from a textfile?

+2  A: 

Yes, you might store it in a simple text file or use a settings file.

Mehrdad Afshari
A: 

Yes, I'd store it in some form of text file, then you can read it on load. It's very easy to implement in Visual Basic and you might even find some samples in Codemonkeys or similar. I'd avoid using the registry. Of course if you want, you could also use some sort of database (Access, SQLITE, etc.) to store the values. But that depends upon the type of data and how much do you need to read/write from it.

Martín Marconcini
It's barely 10 lines really. Seems as though a text file could be the easiest thing to do. Do you have a sample script of it?
Kenny Bones
Well, this might be useful for you: http://www.codeproject.com/KB/files/VbNetClassIniFile.aspx
Martín Marconcini
+2  A: 

Take a look at Application Settings: http://msdn.microsoft.com/en-us/library/0zszyc6e.aspx

Peter Forss
+9  A: 

I believe you're looking for a feature known as Application Settings. This feature will take care of storing settings between instances of the application. The manner in which it stores settings is ClickOnce and User aware so it takes much of the problems out of the picture.

Here's a link to an overview on the topic

JaredPar
You sure this is what I'm looking for? I mean, it seems a bit complicated.. Perhaps a text file will be easiest. The thing is, I kinda want full control of every aspect of the application. Also after it's compiled.
Kenny Bones
@Kenny, Almost 100% sure. It's actually much easier than the tutorial shows. Essentially you open up the Settings page, type the name and type of the setting and you're ready to roll. The Settings feature takes care of many many little issues under the hood that you don't need to be aware of (clickonce security and isolated storage for starters).
JaredPar
Seconded, it's not at all complicated to use. Just define your settings in the project properties, then they can be magically addressed like My.Settings.YourSettingNameHere.
Tiberiu Ana
Well, will this work outside of Visual Studio? I mean, it should be stored somewhere on the root folder, where the exe file is stored. Alot of people may be using this application, and none of them know anything about Visual Studio.
Kenny Bones
@Kenny, yes it will work just fine when deployed.
JaredPar
+4  A: 

Use My.Settings

Dario
A: 

yes you can write to a text file, or try SQLite, which can let your VB program have database capabilities.

http://www.google.com/search?hl=en&q=visual+basic+sqlite&btnG=Search

動靜能量
+1  A: 

I store what I need in a plain text file. I use my own format: First line: lenght of the array or the number of bytes/lines the data needs to be stored. Second line: data types. third line: directories or path info. At the end I store the data.

That's because programming languages can read by characters or by lines. C++ considers either whitespaces and lines.

SQL or Access is when you need to store more complex data than just strings or arrays.

yelinna