VB.net save

Discussion in 'World of SPAM' started by Fexxel, Jun 23, 2009.

  1. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    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
     
  2. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    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)
     
  3. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    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).
     
  4. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    Code (Text):
    1.     Public Function savelist(ByVal lstbox As ListBox, ByVal extension As String, Optional ByVal filedesc As String = "")
    2.         Dim s As New SaveFileDialog
    3.         If extension.Contains(".") = False Then
    4.             extension = "." + extension
    5.         End If
    6.         If filedesc = "" Then
    7.             filedesc = extension + " Files"
    8.         End If
    9.         s.Filter = filedesc + "(*" + extension + ")|*" + extension
    10.         s.ShowDialog()
    11.         Dim a As New StreamWriter(s.FileName)
    12.         s.Dispose()
    13.         For i As Integer = 0 To lstbox.Items.Count - 1
    14.             a.WriteLine(lstbox.Items.Item(i))
    15.         Next
    16.         a.Close()
    17.         a.Dispose()
    18.         Return Nothing
    19.     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):
    1. savelist([yourlistbox], [extension], [a description of the file to display in save dialog (optional)])
     
    Commy likes this.
  5. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Uh Oh!
    Error 1 Identifier expected.
    Doesn't work with multi identifiers (.user.js)... Is there a way to get around it?
    Code (Text):
    1.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         savelist([gm], [.user.js], [.user.js])
    3.     End Sub
     
  6. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    lol the brackets meant fill it in for that :p

    its savelist(gm, .js, .js)
    but yes it only works for one extension thats what i thought you wanted i can fix it
     
  7. Billy

    Billy Level IV

    Joined:
    Feb 21, 2007
    Messages:
    1,856
    Likes Received:
    39
    Code (Text):
    1.     Public Function savelistdialog(ByVal lstbox As ListBox, ByRef extension As String(), Optional ByVal filedesc As String() = Nothing)
    2.         Dim s As New SaveFileDialog
    3.         For i As Integer = 0 To extension.Length - 1
    4.             If extension(i).Contains(".") = False Then
    5.                 extension(i) = "." + extension(i)
    6.             End If
    7.             For x As Integer = 0 To filedesc.Length - 1
    8.                 If filedesc(x) = Nothing Then
    9.                     filedesc(x) = extension(i) + " Files"
    10.                 End If
    11.             Next
    12.             Dim toadd As String = s.Filter + "|"
    13.             If s.Filter = "" Then
    14.                 toadd = ""
    15.             End If
    16.             s.Filter = toadd + filedesc(i) + "(*" + extension(i) + ")|*" + extension(i)
    17.         Next
    18.         s.ShowDialog()
    19.         If s.FileName = "" = False Then
    20.             Dim a As New StreamWriter(s.FileName)
    21.             s.Dispose()
    22.             For i As Integer = 0 To lstbox.Items.Count - 1
    23.                 a.WriteLine(lstbox.Items.Item(i))
    24.             Next
    25.             a.Close()
    26.             a.Dispose()
    27.         End If
    28.         Return Nothing
    29.     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):
    1.  
    2. Dim ext as String() = {".js",".user"}
    3. savelist(gm,ext )
     
    Fexxel likes this.
  8. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Thanks billeh!
    You can lock this or whateva :-D Got it working.
    +Rep'd