|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Beginners needs some help in Writing to text fileHi,
I have a button on a form that, when pressed, adds additional user defined buttons to the form. I need to be able to save the user preferences and thought the best way would be to write the information to a text file. Can anyone supply the code on how to write the newly created buttons name to a text file. As more than 1 new button may be created I want to store the information for each new button on a new line then read the information back in. Thanks Marc Marc wrote:
Show quoteHide quote > Hi, You will probably want to look into the FileStream class.> > I have a button on a form that, when pressed, adds additional user > defined buttons to the form. I need to be able to save the user > preferences and thought the best way would be to write the information > to a text file. > > Can anyone supply the code on how to write the newly created buttons > name to a text file. As more than 1 new button may be created I want to > store the information for each new button on a new line then read the > information back in. > > Thanks > > Marc See here: http://msdn2.microsoft.com/en-us/library/system.io.filestream.aspx just add
Imports System.IO at the very top of the code window (above the Public Class Foo), then you need to make FileStream and a StreamWriter objects ''where you want to write to the file... ''creates the objects used to write to a file Dim fs As New FileStream("C:\Buttons.txt", FileMode.Create, FileAccess.Write) Dim sw As New StreamWriter(fs) ''writeline is the method you want to write a single line to the file, if the ''buttons are in an array, just throw this in a loop sw.WriteLine(Me.Button1.Name) ''VERY IMPORTANT: close the streams so the file will be usable after your app ''is done with it sw.Close() fs.Close() hope this helps -- -iwdu15 Thanks you very much..was most helpful!
I know have a text file where each line represents a button control name. You dont knopw the code to read this file back in and to create a button for each line do you iwdu15 wrote: Show quoteHide quote > just add > > Imports System.IO > > at the very top of the code window (above the Public Class Foo), then you > need to make FileStream and a StreamWriter objects > > ''where you want to write to the file... > ''creates the objects used to write to a file > Dim fs As New FileStream("C:\Buttons.txt", FileMode.Create, FileAccess.Write) > Dim sw As New StreamWriter(fs) > > ''writeline is the method you want to write a single line to the file, if the > ''buttons are in an array, just throw this in a loop > sw.WriteLine(Me.Button1.Name) > > ''VERY IMPORTANT: close the streams so the file will be usable after your app > ''is done with it > sw.Close() > fs.Close() > > > hope this helps > > -- > -iwdu15 Suggest one way is to create a class to hold your user preferences then
serialize this class to a file when the use exits your application then de-serialize it back to the class when your application starts. -- Show quoteHide quoteDennis in Houston "Marc" wrote: > Hi, > > I have a button on a form that, when pressed, adds additional user > defined buttons to the form. I need to be able to save the user > preferences and thought the best way would be to write the information > to a text file. > > Can anyone supply the code on how to write the newly created buttons > name to a text file. As more than 1 new button may be created I want to > store the information for each new button on a new line then read the > information back in. > > Thanks > > Marc > > |
|||||||||||||||||||||||