Configation File

MC² = ?

Member
Joined
Oct 11, 2004
Messages
7
Programming Experience
1-3
Hi

I need Some Help. I have Made a Option Form For my Project i am Making. When the User Choose his options and wants to Close the program. How can i Keep The User Seleted Options for next time He/She Opens it? Could Someone please help with this.

Cheers:)
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
VB.NET:
#Region " Read/Save "
    Public Sub ReadSave(ByVal ReadSave As String)
        If ReadSave = "Read" Then
            Dim SystemSettings As New StreamReader(Application.StartupPath & "\Settings.ini")
                StringValue = SystemSettings.ReadLine()
                BooleanValue = Convert.ToBoolean(SystemSettings.ReadLine())
                IntegerValue = Convert.ToInt32(SystemSettings.ReadLine()) 'Int32 = Integer, int16= Short, int64 = Long
                SystemSettings.Close()
        End If
        If ReadSave = "Save" Then
            Dim SystemSettings As New StreamWriter(Application.StartupPath & "\Settings.ini")
             With SystemSettings
                SystemSettings.WriteLine(StringValue)
                SystemSettings.WriteLine(CStr(BooleanValue))
                SystemSettings.WriteLine(CStr(IntegerValue))
             End With
            SystemSettings.Close()
        End If
    End Sub
#End Region
simply save the stuff needed on program exit, and on program start jes read the value(s) in and there ya go, this is an example sub you'll deffinantly need to modify it for your program(s)
 
Last edited:

MC² = ?

Member
Joined
Oct 11, 2004
Messages
7
Programming Experience
1-3
Name Space

Thank you for your help

Is there any Name Space i will have to import?

Cheers:)
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
prolly not, but jes in case the StreamReader & StreamWriter are both under:
Imports System.IO
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
Paszt said:
The INI approach JuggaloBrotha has shown is perfectly viable, however the new standard is XML. VB8 (framework version 2) has built-in classes that utilize XML to persist settings.

Here is a link to a reusable Class that uses XML configuration files to persist user options: Managing configuration settings persistence in .NET applications

thanx, i'd actually been meaning to research how to 'properly' go about saveing program settings since the system registry isn't recamended anymore
 
Top Bottom