Results 1 to 5 of 5

Thread: direct me somewhere

  1. #1
    Member
    Join Date
    Aug 08
    Posts
    52

    direct me somewhere

    can anyone tell me or link me to what i should be reading up on when it comes to adding and removing items on a list from a listbox. like have a textfield where i type something, click a button. it's added to the list. and beside the add button, it removes what i have selected in the list. the listbox will also be loaded from a .txt document if that means anything.

    thanks in advance.

  2. #2
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,585

    Re: direct me somewhere

    it is probably
    Code:
    list1.removeitem list1.listindex

    fixed
    Last edited by westconn1; Aug 11th, 2012 at 02:50 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,447

    Re: direct me somewhere

    Use this

    Code:
    '~~> Add Item
    Private Sub Command1_Click()
        List1.AddItem Text1.Text
    End Sub
    
    '~~> Remove Selected Item
    Private Sub Command2_Click()
        List1.RemoveItem (List1.ListIndex)
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  4. #4
    PowerPoster
    Join Date
    Feb 06
    Posts
    8,669

    Re: direct me somewhere

    Avoid falling into this odd habit though:
    Code:
    Private Sub Command2_Click()
        List1.RemoveItem (List1.ListIndex)
    End Sub
    Those parentheses are incorrect, and can have nasty unexpected side effects if you don't understand what your use of them is asking the compiler to do. They are not innocuous, though you might get away with it 80% of the time.

    This is a sort of "creeping crud" that happens when people use The Great Pretender (VB.Net) for a while, where Anders and Friends decided to warp decades-old Microsoft Basic syntax.

    What you want here is:
    Code:
    Private Sub Command2_Click()
        List1.RemoveItem List1.ListIndex
    End Sub

  5. #5
    Frenzied Member
    Join Date
    Aug 11
    Location
    B.C., Canada
    Posts
    1,946

    Re: direct me somewhere

    Reading from the .txt document depends on how it is written inside... Is it one entry for each line or is the entries seperates with a coma ","

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •