PureSc0pe Posted August 13, 2004 Posted August 13, 2004 This function is used like this: ''TextBox1.Text = 32 cfg.write("Set Example_1", TextBox1.Text) It Writes to the file exactly like this: Set Example_1 "32" What I need to know is how to make it change only what's in the "" when it's saving the same Example (Set Example_1) instead of just creating a whole new line. Public path As String = Application.StartupPath & "\config.cfg" Public Function Write(ByVal Name As String, ByVal Value As String) As Boolean Dim fs As StreamWriter If File.Exists(path) = False Then ' Create the file. fs = File.CreateText(path) fs.Write(Name & " """ & Value & """" & vbCrLf) fs.Close() Else fs = File.AppendText(path) fs.Write(Name & " """ & Value & """" & vbCrLf) fs.Close() End If End Function Quote It's not impossible, it's Inevitable.
neodammer Posted August 13, 2004 Posted August 13, 2004 (edited) imports system.IO Dim path As String = Application.StartupPath & "\config.cfg" Dim SW As StreamWriter Dim FS As FileStream FS = New FileStream(path, FileMode.Create) SW = New StreamWriter(FS) SW.WriteLine("Set Example_1", TextBox1.Text) SW.WriteLine() SW.WriteLine("BLAH BLAH BLAH NEXT LINE BLAH") SW.Close() FS.Close() ---- this should help you out, remember at the top of the file to import system.io Edited August 13, 2004 by neodammer Quote Enzin Research and Development
PureSc0pe Posted August 13, 2004 Author Posted August 13, 2004 I don't think you see what I'm trying to do...I'm using a class to call the write function because I have numerous things to write. The class I have does everything I need it to except it writes a new line everytime you write. I need it to alter the value in the "" when it applies.ConfigureCFG.zip Quote It's not impossible, it's Inevitable.
neodammer Posted August 13, 2004 Posted August 13, 2004 (edited) Im alittle confused you mean 1. You want the output file to only have one line of text in it at all times or 2. you want lots of lines in the file each with a new whatever is in the "" Type an example of how you want the output file to look like exactly like after a few writes. If your only wanting one line to always be present in the file then you could always delete the file at the beginning of the function. that way only one line of data is always written. Public path As String = Application.StartupPath & "\config.cfg" Public Function Write(ByVal Name As String, ByVal Value As String) As Boolean Dim fs As StreamWriter If File.Exists(path) = False Then ' Create the file. fs = File.CreateText(path) fs.Write(Name & " """ & Value & """" & vbCrLf) fs.Close() Else File.Delete(path) fs = File.CreateText(path) fs.Write(Name & " """ & Value & """" & vbCrLf) fs.Close() End If End Function Edited August 13, 2004 by neodammer Quote Enzin Research and Development
PureSc0pe Posted August 14, 2004 Author Posted August 14, 2004 If it's writing to the same name then I need it to only change the value in the " " and not make a new line. That's all. It will make a new line only if the same name in the file is not already there. Example of the config.cfg file: Set Settings_1 "32" Set Settings_2 "12" Set Settings_3 "1" If I write using this: cfg.write("Set Settings_1", TextBox.Text) and TextBox1.Text = 16 then the file should now look like this: Set Settings_1 "16" Set Settings_2 "12" Set Settings_3 "1" Quote It's not impossible, it's Inevitable.
PureSc0pe Posted August 15, 2004 Author Posted August 15, 2004 Fixed the problem. Quote It's not impossible, it's Inevitable.
Arch4ngel Posted August 17, 2004 Posted August 17, 2004 How did you solved it ? Delete the file and rewrote all the value ? Search for the correct string and replace what's needed ? Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
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.