Re: Save text boxes as file
Hi Adam,
Here's what you want:
Code:
'Write to text file with the Stream Writer Class
Dim sFileText as String
Dim i as Integer
Dim sWriter As IO.StreamWriter = New IO.StreamWriter("C:\Test.txt")
sWriter.WriteLine(i & tb1.text)
i = i + 1
sWriter.WriteLine(i & tb2.text)
i = i + 1
sWriter.WriteLine(i & label.text)
i = i + 1
sWriter.WriteLine(i & "etc.")
'Flush all data to the file.
sWriter.Flush()
Re: Save text boxes as file
Thanks for this. Just starting to test it now. Is it a similar code to loading a file up, and loading each line into text boxes?
Also, how do I go about creating a file? Have got " Dim fso As New FileIO.FileSystem " but there is no option for "create file".
Adam.
Re: Save text boxes as file
look at his code
Code:
Dim sWriter As IO.StreamWriter = New IO.StreamWriter("C:\Test.txt")
Re: Save text boxes as file
After reading your reply, I decided that I had the ultimate blonde moment. It was a directory that needed creating, not a file. This has been sorted now. I also looked into vb classes to reverse the code that I was given, in which I came across Streamreader. I think I am almost there with it.
Code:
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader(DirectCast(ComboBox1.SelectedItem, listItem).fullPath & "/details.adf")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
'line = sr.ReadLine()
Console.WriteLine(line)
Loop Until line Is Nothing
sr.Close()
Catch Exc As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(Exc.Message)
End Try
Now obviosuly that code writes each individulal line to the console. The issue I have here is there is no way to specify where the lines go.
I basically need to say:
line 1 - go to xx.text
line 2 - go to yy.text
I'm wondering how possible it would be to maybe have xx(1).text and xx(2).text. Then do it that way?
Re: Save text boxes as file
Probably a terrible way of doing this. But I've looped the code so it adds all items into a listbox. Then have done the following:
Code:
With variables
MsgBox(.ListView1.Items.Item(0))
MsgBox(.ListView1.Items(0))
.clubname.Text = .ListView1.Items.Item(0).ToString
.address1.Text = .ListView1.Items.Item(1).ToString
.city.Text = .ListView1.Items.Item(2).ToString
.postcode.Text = .ListView1.Items.Item(3).ToString
.telephone.Text = .ListView1.Items.Item(4).ToString
.email.Text = .ListView1.Items.Item(5).ToString
.clubcontact.Text = .ListView1.Items.Item(6).ToString
.teamanager.Text = .ListView1.Items.Item(7).ToString
.membershipcontact.Text = .ListView1.Items.Item(8).ToString
.ListView1.Items.Clear()
End With