CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 1998
    Posts
    3

    How do i save the list from a listbox



    how do i save the list from a listbox control?


    i have a program that creates numbers and puts them into a listbox when they meet certain criteria. I need to be able to save this list..


    is there a better way to list them than a listbox?


    please help.

  2. #2
    Join Date
    Apr 1999
    Posts
    7

    Re: How do i save the list from a listbox



    Try this code:


    dim i%


    open "C:\bbb.txt" for output as #1


    for i%=1 to list1.listcount-1

    print #1,list1.list(i%)

    next


    close #1


    ------


    That's it.


    Felix

  3. #3
    Join Date
    May 2000
    Posts
    21

    Re: How do i save the list from a listbox

    David

    If you want to save it to a text file, I saw a post on microsoft.public.vb.general.discussion that may be what you want. I'll paste it in here but leave eveything (Their names etc...) in it as this isn't my solution! Hope it helps!

    Jerome Norgren

    <Paste>

    Save listbox items to test file
    From: Mike Carlson
    Date Posted: 5/7/00 8:32:22 PM

    Does anybody have any code samples for saving the items in a list box to a
    text file using the common dialog controls?

    Thanks,

    Mike





    Re: Save listbox items to test file
    From: Randy Birch
    Date Posted: 5/7/00 9:14:31 PM

    Off the top of my head ...

    private Sub Command1_Click()

    on Local error GoTo ohmygodtheidiothitcancel

    Dim c as Long
    Dim hFile as Long

    With CommonDialog1

    .CancelError = true
    .InitDir = "d:\"
    .FileName = "untitled.txt"
    .Filter = "Text File;*.txt"

    .ShowSave

    If len(.FileName) then

    MsgBox .FileName

    hFile = FreeFile
    Open .FileName for Output as #hFile

    for c = 0 to List1.ListCount - 1

    print #hFile, List1.List(c)

    next

    Close #hFile

    End If 'If len(.FileName)

    End With 'CommonDialog1

    outtahere:
    Exit Sub

    ohmygodtheidiothitcancel:

    MsgBox "User pressed cancel - do nothing"
    resume outtahere

    End Sub



    --
    Randy Birch, MVP Visual Basic

    http://www.mvps.org/vbnet/
    http://www.mvps.org/ccrp/
    news://news.mvps.org/







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

Featured