|
-
Nov 22nd, 2012, 04:00 PM
#1
Thread Starter
New Member
Listbox Saving Issue
I'm getting errors in this code! Why? Visual Basic 2010
Code:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
SaveFileDialog1.InitialDirectory = "C:\"
SaveFileDialog1.FileName = "Save As..."
SaveFileDialog1.Filter = ("Text Files | *.txt")
SaveFileDialog1.ShowDialog()
Dim w As New IO.StreamWriter(SaveFileDialog1.FileName)
Dim 1 As Integer
For i = 0 To ListBox1.Items.Count = 1
w.WriteLine(ListBox1.Items.Item(i))
Next
w.Close()
End Sub
End Class
-
Nov 22nd, 2012, 04:50 PM
#2
Re: Listbox Saving Issue
For a start, you should not be setting the FileName of the dialogue to "Save As...". That might be appropriate for the Title perhaps.
I don't know that that will cause an error though. Maybe if you were to actually explain the errors to us. Every one has an error message so why keep those a secret from the people whom you want to help you fix them? Are you talking about compilation errors or run time errors? What lines do the errors occur on? Please provide a FULL and CLEAR description of the problem.
-
Nov 22nd, 2012, 04:59 PM
#3
Thread Starter
New Member
Re: Listbox Saving Issue
I aplogize, I am getting an error on the "1" and the "i".
-
Nov 22nd, 2012, 05:24 PM
#4
Re: Listbox Saving Issue
 Originally Posted by lacobus
I'm getting errors in this code! Why? Visual Basic 2010
Code:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
SaveFileDialog1.InitialDirectory = "C:\"
SaveFileDialog1.FileName = "Save As..."
SaveFileDialog1.Filter = ("Text Files | *.txt")
SaveFileDialog1.ShowDialog()
Dim w As New IO.StreamWriter(SaveFileDialog1.FileName)
Dim 1 As Integer
For i = 0 To ListBox1.Items.Count = 1
w.WriteLine(ListBox1.Items.Item(i))
Next
w.Close()
End Sub
End Class
You can't use a number for an identifier. Try something like Dim i as Integer instead.
Code:
For i As Integer = 0 To ListBox1.Items.Count
...
Last edited by Arve K.; Nov 22nd, 2012 at 05:37 PM.
-
Nov 22nd, 2012, 05:32 PM
#5
Re: Listbox Saving Issue
try this:
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SaveFileDialog1.InitialDirectory = "C:\"
SaveFileDialog1.Title = "Save As..."
SaveFileDialog1.Filter = "Text Files TXT (*.txt)| *.txt"
SaveFileDialog1.FilterIndex = 0
If SaveFileDialog1.ShowDialog() = dialogresult.ok Then
IO.File.WriteAllLines(SaveFileDialog1.FileName, ListBox1.Items.cast(Of String).toarray)
End If
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|