Results 1 to 7 of 7

Thread: Saving Text from a Listbox

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    Sydney, Nova Scotia
    Posts
    55
    Hi I'm trying to save text that piles up in a listbox while my executable is running.

    For example, a user would like to save their session, so they click a button and the contents in a listbox are saved to a text file or a log......

    This seems easy enough to do?


    Thanks For any help........

    Vince McMullin
    Aka Vam, Vinny Mac

    Its just that simple

  2. #2
    Guest
    Try this:

    Code:
    Private Sub Command1_Click()
    Dim i as Integer
    
    Open "C:\Saved.txt" For Output As #1
    For i = 0 to List1.ListCount
        Print #1, List1.List(i)
    Next i
    Close #1
    
    End Sub
    Sunny


  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    Sydney, Nova Scotia
    Posts
    55
    What if don't always know where the user will be installing my program, so therefore the textfile won't be accompained it.....

    ?
    Vince McMullin
    Aka Vam, Vinny Mac

    Its just that simple

  4. #4
    Guest
    Then you can use the API to find out the Windows directory and put your file in there, everyone's bound to have a Windows directory.

    Theres an example on how to do this in VB World at http://www.vb-world.net/tips/tip30.html


    Sunny

  5. #5
    Guest
    Use App.Path to get the directory of your App.

    Code:
    Open App.Path & "\MyFile.txt" for Output As #1
    For I = 0 to List1.ListCount
        Print #1, List1.List(I)
    Next I
    Close #1

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2000
    Location
    Sydney, Nova Scotia
    Posts
    55
    Thanks everyone, that worked great!


    Now what about textboxes and saving text from them? Such as a users name. I want it all to happen on the same click


    Heres my current code:

    Private Sub Save_Click()
    Dim i As Integer

    Open "events.txt" For Output As #1
    For i = 0 To Events.ListCount
    Print #1, Events.List(i)
    Next i
    For i = 0 To Players.ListCount
    Print #1, Players.List(i)
    Next i
    Close #1

    End Sub

    Vince McMullin
    Aka Vam, Vinny Mac

    Its just that simple

  7. #7
    Guest
    To save the text from TextBoxes.

    Code:
    Open "MyFile.txt" For Output As #1
    Print #1, Text1.Text
    Close #1
    There, if this is saved with the rest, your code should be similar to the following:

    Code:
    Private Sub Save_Click()
    
        Dim i As Integer
        
        Open "events.txt" For Output As #1
        
            For i = 0 To Events.ListCount
                Print #1, Events.List(i)
            Next i
        
            For i = 0 To Players.ListCount
                Print #1, Players.List(i)
            Next i
            
            'Save the text from Text1 as well
            Print #1, Text1.Text
            
        Close #1
    
    End Sub

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