Help saving listbox

__Doc_

New member
Joined
Aug 23, 2008
Messages
3
I have coded in VB6 for a while now and Ive decided to code in VB9.
I have the OpenFileDialog(Dim ofd As New OpenFileDialog), It loads my .txt files into my List1.

How can i save my list2 to any file, preferably .txt
I would obviously have, .Filter = "Text Files (*.txt)|*.txt| All Files(*.*)|*.*"

Im just confused about the code for saving. Isnt like VB6.

Any help would be appreciated. ty
-Gabriel
 
What is List1? A List(Of T)? A ListBox or ListView? And how are you loading the text file? Or are you loading a list of filenames?
 
List1 = listbox1

Im saving a listbox

for instants, say you have this

dim x as integer
for x = 0 to 10

With List1
.Items.Add(i%)
End With
next i%
i% = empty

so now list1 has the items

0
1
2
3
4
5
6
7
8
9
10


i need to save the content of list1 to a txt file. In that order.

my VB6 code would look like this, I just need this action in vb.net
thanks


Code:
Dim X As Long

  With CD1
    .DialogTitle = "Save List"                                                                
    .Filter = "Text files (*.txt)|*.txt|Dictionary files(*.dic)|*.dic|All files (*.*)|*.*"   
    .CancelError = True                                                    
    .ShowSave                                     

    Open .FileName For Output As #2
    For X& = 0 To List1.ListCount - 1

      Print #2, List1.List(X&)
    Next X&
    Close #2

  End With    {End Of}-> With CD1
 
Code:
   Dim cd1 As New SaveFileDialog
        With cd1
            .Title = "Save List"
            .Filter = "Text files (*.txt)|*.txt|Dictionary files(*.dic)|*.dic|All files (*.*)|*.*"
            .ShowDialog()

            Dim fs As New FileStream(.FileName, FileMode.Create)
            Dim sw As New StreamWriter(fs)
            For Each s As String In List1.Items

                sw.WriteLine(s)
            Next
            sw.Close()


        End With    {End Of}-> With CD1

is probably the closest / easiest translation.
 
Back
Top