|
-
Nov 19th, 2003, 10:44 AM
#1
Thread Starter
New Member
Export a List Box
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.
-
Nov 19th, 2003, 11:32 AM
#2
Re: Export a List Box
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.
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.
-
Nov 19th, 2003, 11:39 AM
#3
Thread Starter
New Member
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.
-
Nov 19th, 2003, 11:45 AM
#4
Re: Re: Export a List Box
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.
damn it, why do you have to be all nice?
-
Nov 19th, 2003, 11:49 AM
#5
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.
[vbcode][/vbcode]
-
Nov 19th, 2003, 12:03 PM
#6
Re: Re: Re: Export a List Box
Originally posted by kasracer
damn it, why do you have to be all nice?
His post count was 1. You have to make them a regular customer before the abuse starts.
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
-
Nov 19th, 2003, 12:11 PM
#7
Thread Starter
New Member
Thanks for that. Its working now. And also thanks for correcting the post i'll know for next time.
Paul.
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
|