delete button for listbox

hello,
I have a listbox that is showing 3 records
from a ini file, that has 3 lines like this
emai1@domain.com;password1;
emai2@domain.com;password2;
emai3@domain.com;password3;

the listbox only shows the email, but
how can I make a button that can delete
the record I select?
apleloisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Private Sub Command1_Click()
    Dim i As Integer
    i = List1.ListIndex
    If i <> -1 Then
        List1.RemoveItem i
    End If
End Sub
apleloisAuthor Commented:
thanks Idle_Mind, for your fast response.
yes is working but is not deleting it from the account.ini file.
BrianGEFF719Commented:
aplelois,
As I mentioned in your other thread, your life would be alot easier if you were to use a more organized method for storing data. Perhaps consider using the GetPrivateProfile() Functions in the Windows API.

Brian
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

apleloisAuthor Commented:
BrianGEFF719, so I just create the mudule that rbgCODE provided ?
apleloisAuthor Commented:
BrianGEFF719 , whats your point?
BrianGEFF719Commented:
My point is this: You can store your data in a way that makes it much easier to add,modify and delete.

For example even if you were to use the registry, wouldnt your life be easier if you could get the un/pw like this:

un = getsetting("myApp","mySec","username")
pw = getsetting("myApp","mySec","password")

Thats the point I'm trying to make, since you are storing the passwords/emails in clear text you might as well take advantage of the predefined functions for handling storage of settings.


Brian
BrianGEFF719Commented:
Idle_Mind provided a correct solution, this question can be closed.
apleloisAuthor Commented:
humm BrianGEFF719 I am really confused sorry, im not a VB6 expert.
junglerover77Commented:
Make a text file "C:\1.ini" with the following content:
emai1@domain.com;password1;
emai2@domain.com;password2;
emai3@domain.com;password3;

Then, build a form, put a ListBox and a CommandButton on it. Copy the following code into the form:

Dim fso As Object
   
Private Sub Command1_Click()
    Dim ts As Object
    Dim sContent As String
    Dim vRows
    Dim i As Long
   
    If List1.ListIndex <> -1 Then
        Set ts = fso.OpenTextFile("c:\1.ini")
        sContent = ts.ReadAll
        ts.Close
        vRows = Split(sContent, vbCrLf)
       
        sContent = ""
        For i = 0 To UBound(vRows)
            If i <> List1.ListIndex And vRows(i) <> "" Then sContent = sContent + vRows(i) + vbCrLf
        Next
       
        Set ts = fso.OpenTextFile("c:\1.ini", ForWriting)
        ts.Write (sContent)
        ts.Close
       
        List1.RemoveItem (List1.ListIndex)
    End If
End Sub

Private Sub Form_Load()
    Dim ts As Object
    Dim i As Long
    Dim sContent As String
    Dim vRows, vCells
   
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile("c:\1.ini")
    sContent = ts.ReadAll
    ts.Close
   
    vRows = Split(sContent, vbCrLf)
    For i = 0 To UBound(vRows)
        vCells = Split(vRows(i), ";")
        If UBound(vCells) >= 0 Then List1.AddItem (vCells(0))
    Next
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
apleloisAuthor Commented:
ok working nicely but when I try to delete it makes this line yellow
      Set ts = fso.OpenTextFile("c:\1.ini", ForWriting)
junglerover77Commented:
Did you set a breakpoint on that statement?

If not, please show me the error message.
apleloisAuthor Commented:
no breakpoint.
Run-time error '5':
invalid procedure call or argument
junglerover77Commented:
Just change the following statement
        Set ts = fso.OpenTextFile("c:\1.ini", ForWriting)
to
        Set ts = fso.OpenTextFile("c:\1.ini", 2)

Then everything will be all right.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.