__Doc_ Posted August 23, 2008 Posted August 23, 2008 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 Quote
Leaders snarfblam Posted August 23, 2008 Leaders Posted August 23, 2008 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? Quote [sIGPIC]e[/sIGPIC]
__Doc_ Posted August 24, 2008 Author Posted August 24, 2008 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 Quote
Administrators PlausiblyDamp Posted August 24, 2008 Administrators Posted August 24, 2008 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
__Doc_ Posted August 24, 2008 Author Posted August 24, 2008 awesome, Thank you very much. You guys are great. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.