Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have coded in VB6 for a while now and I've 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(*.*)|*.*"

 

I'm just confused about the code for saving. Isn't like VB6.

 

Any help would be appreciated. ty

-Gabriel

Posted

List1 = listbox1

 

I'm 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

 

''
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

  • Administrators
Posted


  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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...