Lanc1988 Posted December 29, 2004 Posted December 29, 2004 I have a listbox and the user is able to add items to it using a textbox, so i wanna be able to save that list to a .dat file, im just not sure how to get it to loop until all items are saved.. i can do it with individual textboxes and things like that.. Here is the code I wanna use, just need to make it save everything in the list: Dim swMisc As System.IO.StreamWriter = _ New System.IO.StreamWriter(Application.StartupPath & "\Settings\listboxitems.dat", False) swMisc.WriteLine(Me.checkedlistbox1.Text) swMisc.Flush() swMisc.Close() swMisc = Nothing also, is it possible to save if the user checked the item in the listbox (cuz im using a checked listbox) Quote
Diesel Posted December 30, 2004 Posted December 30, 2004 (edited) Attached FileSaveListtoFile.zip Edited December 30, 2004 by PlausiblyDamp Quote
Lanc1988 Posted December 30, 2004 Author Posted December 30, 2004 It is giving me an error: The application for project 'C:\SaveListtoFile\SaveListtoFile.csproj' is not installed. Make sure the application for the project type (.csproj) is installed. I ran the application in the debug folder and it works just how I need it to.. just can't see the code. Thanks Quote
Diesel Posted December 30, 2004 Posted December 30, 2004 Did you unzip the csproj file? Either way, just open the form1.cs file. Quote
Lanc1988 Posted December 30, 2004 Author Posted December 30, 2004 I tried that, i also tried adding that form to an existing project.. but still can't get it to work.. could it be that i only have visual basic.net standard edition? Could you just post the code that you have under the two save buttons? Quote
Administrators PlausiblyDamp Posted December 30, 2004 Administrators Posted December 30, 2004 It looks like the attachment is C#, if you only have VB installed then you will get an error opening the project. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Lanc1988 Posted December 30, 2004 Author Posted December 30, 2004 that would explain it.. well.. can anybody else post the code that would be used for vb.net to save the items in a checkedlistbox? Quote
coldfusion244 Posted December 30, 2004 Posted December 30, 2004 that would explain it.. well.. can anybody else post the code that would be used for vb.net to save the items in a checkedlistbox? How about try using the C# to VB Translator in archangels sig... http://authors.aspalliance.com/aldotnet/examples/translate.aspx Quote -Sean
Lanc1988 Posted December 30, 2004 Author Posted December 30, 2004 i can only translate if I have the code, which i can't see because I can't open the project. Quote
Administrators PlausiblyDamp Posted December 31, 2004 Administrators Posted December 31, 2004 You could still open the .cs file in somethng like notepad though... Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Lanc1988 Posted December 31, 2004 Author Posted December 31, 2004 ok, thanks for the opening in notepad idea.. so now I translated it to vb.net and i found the part that saves the items in a checkedlistbox which is: Dim fs As New System.IO.FileStream("list.dat", System.IO.FileMode.Create) Dim sw As New System.IO.StreamWriter(fs) Dim obj As Object For Each obj In checkedListBox1.Items sw.WriteLine(obj.ToString()) Next obj sw.Close() Now, what would be the code to load the items in the .dat file into the checkedlistbox? Thanks Diesel Quote
Diesel Posted December 31, 2004 Posted December 31, 2004 checkedListBox1.Clear() Dim fs As New System.IO.FileStream("list.dat", System.IO.FileMode.Create) Dim sr As New System.IO.StreamReader(fs) Dim obj As Object While (sr.Read()) checkedListBox1.Items.Add(sr.ToString()) End While sr.Close() [/Code] Quote
Lanc1988 Posted December 31, 2004 Author Posted December 31, 2004 the saving the items in the listbox works perfectly but when I put the code in my load event to load the items into the textbox, my program for some reason won't even open.. i have to press the stop button because I can't even see the form. heres the load code to get the items from the .dat file: Dim Miscfs As New System.IO.FileStream(Application.StartupPath & "MiscGoals.dat", System.IO.FileMode.Create) Dim Miscsr As New System.IO.StreamReader(Miscfs) Dim obj As Object While (Miscsr.Read()) listboxMiscGoals.Items.Add(Miscsr.ToString()) End While Miscsr.Close() Quote
Diesel Posted December 31, 2004 Posted December 31, 2004 Use FileMode.Open instead of FileMode.Create Quote
Lanc1988 Posted December 31, 2004 Author Posted December 31, 2004 i changed it to FileMode.Open and it still won't even load the form.. can't see anything EDIT: I just removed this section of code from the code to load the items: While (Miscsr.Read()) listboxMiscGoals.Items.Add(Miscsr.ToString()) End While Now the form will display when I run the program.. but of course it isn't loading the items since that is the part that does it. So I think that something is wrong with that section of the code. Quote
Lanc1988 Posted January 1, 2005 Author Posted January 1, 2005 maybe its the While and End While parts...? 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.