Results 1 to 4 of 4

Thread: Save As help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    148

    Save As help

    I've searched for this but I can't find it:

    I have a listbox with numbers and I just want to save them when the user clicks Save_Click() as a SAVE AS function. I've used this, but I get errors:

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3. With CommonDialog1  'open a with statement as there is a lot of code
    4.      .DialogTitle = "Save"  'sets the dialog title
    5.      .InitDir = "C:\"  'sets the initial directory
    6.      .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"  'sets the file
    7.      'types
    8.  
    9.      .ShowSave  'show the dialog
    10. End With
    11.  
    12. List2.SaveAs CommonDialog1.FileName  'save to the specified file
    13.  
    14. End Sub

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Save As help

    Listboxes don't have a save command and hence you need to loop through the items to print them out individally.
    VB Code:
    1. With CommonDialog1  'open a with statement as there is a lot of code
    2.      .DialogTitle = "Save"  'sets the dialog title
    3.      .InitDir = "C:\"  'sets the initial directory
    4.      .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"  'sets the file
    5.      'types
    6.  
    7.      .ShowSave  'show the dialog
    8. End With
    9.  
    10. Open CommonDialog1.FileName For Output As #1
    11.     For x = 0 To List2.ListCount
    12.         Print #1, List2.List(x)
    13.     Next
    14. Close #1

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Save As help

    Listboxes don't have any "SaveAs" methods - you have to do it yourself:
    VB Code:
    1. Private Sub Command2_Click()
    2. Dim i%
    3.  
    4.     Open App.Path & "\numbers.txt" For Output As #1
    5.         For i = 0 To List1.ListCount - 1
    6.             Print #1, List1.List(i)
    7.         Next i
    8.     Close #1
    9.  
    10. End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    148

    Re: Save As help

    great, works great. Thanks guys.
    Last edited by takamine334; Nov 24th, 2005 at 07:28 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width