tags:

views:

29

answers:

2

If i have information (for example a name) in a label on a form in Visual Basic, how do I save this information in a .txt file?

Thanks

+1  A: 

You can use the classes in the System.IO namespace. Look at File and its methods.

This example uses one overload of WriteAllText:

File.WriteAllText("Path To Text File.txt", myLabel.Text)

It will write the text value of the myLabel control to the specifies text file.

Oded
A: 

You can use file system object for ealier versions of Visual basic.

' VBScript Dim fso, MyFile Set fso = CreateObject("Scripting.FileSystemObject") Set MyFile = fso.CreateTextFile("c:\testfile.txt", True) MyFile.WriteLine(label.caption) MyFile.Close http://msdn.microsoft.com/en-us/library/z9ty6h50(VS.85).aspx

or

Sub Create_File() Dim fso, txtfile Set fso = CreateObject("Scripting.FileSystemObject") Set txtfile = fso.CreateTextFile("c:\testfile.txt", True) txtfile.Write (lable.caption) ' Write a line. ' Write a line with a newline character. txtfile.WriteLine("Testing 1, 2, 3.") ' Write three newline characters to the file. txtfile.WriteBlankLines(3) txtfile.Close End Sub msdn.microsoft.com/en-us/library/aa263346(VS.60).aspx

John