Hi i am using VB2008 express
As a learning project I am trying to code a simple program that uses varied options, with no other function other than to familiarize myself
I have a textbox, radiobuttons, checked listbox, several dialogues etc. I have had a few problems but have managed to solve through trial and error
However, i have reached a point where i need some help
I would like to save the selected items within a checkedlistbox to a "*.txt" file on a button click event
Here is my code
On debug I check a number of lines, on button click the openfile dialogue opens and allows me to save a file, the problem i have is that the saved file only has one line which is actually the selected(highlighted) line of the checked list box instead of the checkeditems
I have changed the code to test a few things and instead of writing to file, i outputed the results to a textbox, and also messagebox with no apparent problems, so i cant see where i am going wrong
Any help with this is greatly appreciated
As a learning project I am trying to code a simple program that uses varied options, with no other function other than to familiarize myself
I have a textbox, radiobuttons, checked listbox, several dialogues etc. I have had a few problems but have managed to solve through trial and error
However, i have reached a point where i need some help
I would like to save the selected items within a checkedlistbox to a "*.txt" file on a button click event
Here is my code
VB.NET:
Private Sub SaveSelected_Click()
Try
With SaveFileDialog1
.AddExtension = True
.CheckPathExists = True
.CreatePrompt = False
.OverwritePrompt = True
.ValidateNames = True
.ShowHelp = True
.DefaultExt = "txt"
.FileName = ""
.Filter = "Text files (*.txt)|*.txt|" & "All files|*.*"
.FilterIndex = 1
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
My.Computer.FileSystem.WriteAllText(.FileName, CheckedListBox1.CheckedItems(i), False)
Next
End If
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
End Try
End Sub
On debug I check a number of lines, on button click the openfile dialogue opens and allows me to save a file, the problem i have is that the saved file only has one line which is actually the selected(highlighted) line of the checked list box instead of the checkeditems
I have changed the code to test a few things and instead of writing to file, i outputed the results to a textbox, and also messagebox with no apparent problems, so i cant see where i am going wrong
Any help with this is greatly appreciated