CALLING ALL PWNSOME PEOPLE!! How do I save the contents of a listbox to a file of an odd extension... IE: .user.js or.. .xml ? A save function would rock :-D
you need to use a streamwriter i can get some code to you in a little while (im on my mac atm and parallels is SO slow)
WOOT I'M NOT THE ONLY PERSON ONLINE/AWAKE!!! Streamwriter. Got it. I have parallels btw. I've ran multiple parralels at the same time (XP/Ubuntu) and its (after tests): 84% of the speed excpected from the actual OS. It just takes a while for each Virtual Machine to load (there are good reasons for that).
Code (Text): Public Function savelist(ByVal lstbox As ListBox, ByVal extension As String, Optional ByVal filedesc As String = "") Dim s As New SaveFileDialog If extension.Contains(".") = False Then extension = "." + extension End If If filedesc = "" Then filedesc = extension + " Files" End If s.Filter = filedesc + "(*" + extension + ")|*" + extension s.ShowDialog() Dim a As New StreamWriter(s.FileName) s.Dispose() For i As Integer = 0 To lstbox.Items.Count - 1 a.WriteLine(lstbox.Items.Item(i)) Next a.Close() a.Dispose() Return Nothing End Function this should work i just made it so there might be some small errors. just tell me if there are usage: Code (Text): savelist([yourlistbox], [extension], [a description of the file to display in save dialog (optional)])
Uh Oh! Error 1 Identifier expected. Doesn't work with multi identifiers (.user.js)... Is there a way to get around it? Code (Text): Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click savelist([gm], [.user.js], [.user.js]) End Sub
lol the brackets meant fill it in for that its savelist(gm, .js, .js) but yes it only works for one extension thats what i thought you wanted i can fix it
Code (Text): Public Function savelistdialog(ByVal lstbox As ListBox, ByRef extension As String(), Optional ByVal filedesc As String() = Nothing) Dim s As New SaveFileDialog For i As Integer = 0 To extension.Length - 1 If extension(i).Contains(".") = False Then extension(i) = "." + extension(i) End If For x As Integer = 0 To filedesc.Length - 1 If filedesc(x) = Nothing Then filedesc(x) = extension(i) + " Files" End If Next Dim toadd As String = s.Filter + "|" If s.Filter = "" Then toadd = "" End If s.Filter = toadd + filedesc(i) + "(*" + extension(i) + ")|*" + extension(i) Next s.ShowDialog() If s.FileName = "" = False Then Dim a As New StreamWriter(s.FileName) s.Dispose() For i As Integer = 0 To lstbox.Items.Count - 1 a.WriteLine(lstbox.Items.Item(i)) Next a.Close() a.Dispose() End If Return Nothing End Function the code is a little messy and its a little more difficult to define but i was just doing this real quickly so im sure you could fix it up and make it a lot better your code above would read Code (Text): Dim ext as String() = {".js",".user"} savelist(gm,ext )