• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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?
0
aplelois
Asked:
aplelois
  • 6
  • 4
  • 3
  • +1
1 Solution
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now