cdoverlaw Posted October 12, 2003 Posted October 12, 2003 how do i get a vb.net program to save settings (like which CheckBoxs are checked) into a text file and then load them when the program starts Jonathan Quote
wyrd Posted October 12, 2003 Posted October 12, 2003 Use XML serialization. Quote Gamer extraordinaire. Programmer wannabe.
cdoverlaw Posted October 13, 2003 Author Posted October 13, 2003 i havent got a clue how and wot that is Quote
*Experts* mutant Posted October 13, 2003 *Experts* Posted October 13, 2003 Serialization is a process of saving a state of an object to a file with exact properties that were set to it during serialization. Its like putting an object into a file for storage :). Quote
cdoverlaw Posted October 13, 2003 Author Posted October 13, 2003 ok so how do it then, can u tell me what code is required Quote
Mohsen Posted October 30, 2003 Posted October 30, 2003 Why do u want to save them into a text file? Can't you save the settings into a table inside a database? If yes, i'll teach you how. Mohsen Quote
cdoverlaw Posted October 30, 2003 Author Posted October 30, 2003 I dont mind what way they are saved, so any help you can offer would be realy appreciated, i just need all settings to be saved so that the user dosent have to change their settings every time they launch the program Jonathan Quote
Mohsen Posted October 30, 2003 Posted October 30, 2003 Listen Jonathan, the professional way to do what you want is by connecting you application to a database, save everything the user does in an organized tables, and then on load you take the informatoin from the database. But now I'm not gonna teach you that because it need time, so I'll teach you how to write the settings into a file. Try the following: Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Me.Invoke(New SettingInvoke(AddressOf Me.GetSetting)) ' SettingThread.Start() GetSetting() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim FileWritrer As New IO.StreamWriter("C:\SavingSetting.txt") FileWritrer.WriteLine(" CheckBox2," & CheckBox2.Checked) FileWritrer.WriteLine(" " & TextBox1.Text) FileWritrer.Flush() 'make sure everything is dumped into the file FileWritrer.Close() End Sub ' Private SettingThread As New Threading.Thread(AddressOf GetSetting) Private Sub GetSetting() Dim FileReader As New IO.StreamReader("C:\SavingSetting.txt") Dim i As Integer = 0 Dim s, e As String Dim x, y As Integer While FileReader.Read() <> -1 If i = 0 Then s = FileReader.ReadLine() s = s.Substring(s.LastIndexOf(",") + 1) If s.Equals("False") Then CheckBox2.Checked = False Else CheckBox2.Checked = True End If Else TextBox1.Text = FileReader.ReadLine() End If i = i + 1 End While FileReader.Close() ' SettingThread.Abort() End Sub once you click on button2, the information are saved on a file on the C drive. Once you load the form, the settings are loaded again. Quote
cdoverlaw Posted October 31, 2003 Author Posted October 31, 2003 Sorry, i have been working, i will try it tommorow and post what happens, Quote
cdoverlaw Posted November 1, 2003 Author Posted November 1, 2003 Yup, like i thought, i am having problems, I have attached my program, (without any of the saving setting code) Well the first problem is that when i use the code 'Me.Invoke(New SettingInvoke(AddressOf Me.GetSetting)) ' SettingThread.Start() GetSetting() I get an error with the GetSetting() saying C:\Documents and Settings\Jonathan.N-FORCE\My Documents\Visual Studio Projects\docked sidebar\XPEBarTest\Sidebar.vb(620): Argument not specified for parameter 'AppName' of 'Public Function GetSetting(AppName As String, Section As String, Key As String, [Default As String = ""]) As String'. C:\Documents and Settings\Jonathan.N-FORCE\My Documents\Visual Studio Projects\docked sidebar\XPEBarTest\Sidebar.vb(620): Argument not specified for parameter 'Key' of 'Public Function GetSetting(AppName As String, Section As String, Key As String, [Default As String = ""]) As String'. C:\Documents and Settings\Jonathan.N-FORCE\My Documents\Visual Studio Projects\docked sidebar\XPEBarTest\Sidebar.vb(620): Argument not specified for parameter 'Section' of 'Public Function GetSetting(AppName As String, Section As String, Key As String, [Default As String = ""]) As String'. docked sidebar.zip Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.