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?
 
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Private Sub Command1_Click()
    Dim i As Integer
    i = List1.ListIndex
    If i <> -1 Then
        List1.RemoveItem i
    End If
End Sub
0
 
apleloisAuthor Commented:
thanks Idle_Mind, for your fast response.
yes is working but is not deleting it from the account.ini file.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
0
 
apleloisAuthor Commented:
BrianGEFF719, so I just create the mudule that rbgCODE provided ?
0
 
apleloisAuthor Commented:
BrianGEFF719 , whats your point?
0
 
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
0
 
BrianGEFF719Commented:
Idle_Mind provided a correct solution, this question can be closed.
0
 
apleloisAuthor Commented:
humm BrianGEFF719 I am really confused sorry, im not a VB6 expert.
0
 
apleloisAuthor Commented:
ok working nicely but when I try to delete it makes this line yellow
      Set ts = fso.OpenTextFile("c:\1.ini", ForWriting)
0
 
junglerover77Commented:
Did you set a breakpoint on that statement?

If not, please show me the error message.
0
 
apleloisAuthor Commented:
no breakpoint.
Run-time error '5':
invalid procedure call or argument
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.