I have some code that exoprts the contents of a List box to a txt fle,
It does about 882 lines then stops writing to the file, even though the code still loops through the rest of the list box which has 902 items in it.
Thanks in Advnace.
Paul.
Printable View
I have some code that exoprts the contents of a List box to a txt fle,
It does about 882 lines then stops writing to the file, even though the code still loops through the rest of the list box which has 902 items in it.
Thanks in Advnace.
Paul.
Hello, welcome to the forums this looks like your first post. There is no question in your post and there is not enough information to answer the implied question of what is wrong with your code. When asking questions you should try and be specific, post code, and explain exactly what the problem is providing either what should happen but doesn't or any error messages you receive. So if you want to post the code you are using to export the listbox then we'll take a look and figure out why it stops writing to the file.Quote:
Originally posted by paulho
I have some code that exoprts the contents of a List box to a txt fle,
It does about 882 lines then stops writing to the file, even though the code still loops through the rest of the list box which has 902 items in it.
Thanks in Advnace.
Paul.
Here is the code:
If MsgBox(Prompt:="Would you like to save results to txt file ?", _
Buttons:=MsgBoxStyle.YesNo + vbQuestion, _
Title:="Save Results") = MsgBoxResult.Yes Then
lstComputers.SelectedIndex = 0
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
Dim i As Integer
oWrite = oFile.CreateText(Application.StartupPath & "Export.txt")
For i = 1 To lstComputers.Items.Count - 1
oWrite.WriteLine(lstComputers.Text)
'If lstComputers.SelectedIndex <> lstComputers.Items.Count - 1 Then
lstComputers.SelectedIndex = lstComputers.SelectedIndex + 1
'End If
Next
lstComputers.SelectedIndex = 0
End If
This VB.Net is all new to me. I've only been using it for 3 days.
Paul.
damn it, why do you have to be all nice?Quote:
Originally posted by Edneeis
Hello, welcome to the forums this looks like your first post. There is no question in your post and there is not enough information to answer the implied question of what is wrong with your code. When asking questions you should try and be specific, post code, and explain exactly what the problem is providing either what should happen but doesn't or any error messages you receive. So if you want to post the code you are using to export the listbox then we'll take a look and figure out why it stops writing to the file.
[vbcode][/vbcode]Quote:
Originally posted by paulho
Here is the code:
VB Code:
If MsgBox(Prompt:="Would you like to save results to txt file ?", _ Buttons:=MsgBoxStyle.YesNo + vbQuestion, _ Title:="Save Results") = MsgBoxResult.Yes Then lstComputers.SelectedIndex = 0 Dim oFile As System.IO.File Dim oWrite As System.IO.StreamWriter Dim i As Integer oWrite = oFile.CreateText(Application.StartupPath & "Export.txt") For i = 1 To lstComputers.Items.Count - 1 oWrite.WriteLine(lstComputers.Text) 'If lstComputers.SelectedIndex <> lstComputers.Items.Count - 1 Then lstComputers.SelectedIndex = lstComputers.SelectedIndex + 1 'End If Next lstComputers.SelectedIndex = 0 End If
This VB.Net is all new to me. I've only been using it for 3 days.
Paul.
His post count was 1. You have to make them a regular customer before the abuse starts.Quote:
Originally posted by kasracer
damn it, why do you have to be all nice?
There isn't a need to preface any parameters with the parameter name (i.e. Prompt:=) unless you want to. That is more of a VBA type syntax. Also there isn't a need to select an item in the listbox you can loop through all of its items via the Items property which is a collection of those items. Here is an example to learn from:
VB Code:
If MsgBox("Would you like to save results to txt file ?", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "Save Results") = MsgBoxResult.Yes Then 'create file Dim filepath As String = IO.Path.Combine(Application.StartupPath, "Export.txt") Dim sw As New IO.StringWriter(New IO.FileStream(filepath, IO.FileMode.CreateNew)) 'loop through the items 'there isn't a need to select them though Dim item As String 'assuming you have strings in the listbox For Each item In lstComputers.Items 'write the item to a line in the file sw.WriteLine(item) Next 'close file sw.Close() End If
Thanks for that. Its working now. And also thanks for correcting the post i'll know for next time.
Paul.