How to take all data in my listbox to a txt

September 24, 2011 at 04:48:01
Specs: Windows Vista
I have a list box and a button delete. When I load my form all information in my txt file to the listbox. So when I press delete the item that I've selected is remove but I would like to save the changes and in the text file also it is remove. can someone help me.

See More: How to take all data in my listbox to a txt

Report •

September 24, 2011 at 12:04:07
To save the changes you have to write it out.

Report •

September 29, 2011 at 03:26:58
Here is a quick example iv written. Its not brilliant but it works.
You will need:

1 UserForm (Called UserForm1)
1 Listbox (Called Listbox1)
1 CommandButton (Called CommandButton1)
1 CommandButton (Called CommandButton2)
1 Text File (Called C:\test.txt)

Dim nCount, nValue, TheFilePath

Private Sub UserForm_Activate()
    TheFilePath = "C:\test.txt"
End Sub

Public Sub ReadFile()

    Open TheFilePath For Input As #1 ' Open file for input.
    nCount = 0
    Do While Not EOF(1) ' Loop until end of file.
    Input #1, nValue
           UserForm1.ListBox1.AddItem nValue, nCount
            nCount = nCount + 1
    Close #1 ' Close file.
End Sub

Private Sub CommandButton1_Click()
    UserForm1.ListBox1.RemoveItem (ListBox1.ListIndex)
End Sub

Private Sub CommandButton2_Click()
    Kill TheFilePath
    Open TheFilePath For Append As #1

        For i = 0 To ListBox1.ListCount - 1

            Print #1, ListBox1.List(i)
        Next i

    Close #1

End Sub

Report •

October 2, 2011 at 04:16:44
Thank you i'll try it

Report •

Related Solutions

Ask Question