CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: VB Help

  1. #1
    Join Date
    Apr 2001
    Location
    Chicago, IL
    Posts
    27

    VB Help

    Does anyone know what code to add to this existing code so that a msgbox pops up if there are no items in the list box and I push the remove button. Thank you.

    Private Sub cmdRemove_Click()
    Dim i As Integer

    For i = lstShopping.ListCount - 1 To 0 Step -1

    If lstShopping.Selected(i) = True Then
    lstShopping.RemoveItem i
    End If
    Next i
    End Sub

    Archie Kantzavelos

  2. #2
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: VB Help

    Try This:

    If lstShopping.ListCount < 1 then
    MsgBox "ListBox is empty", vbExclamation + vbOKOnly, "ListBox error"
    End If





    Kris
    Software Engineer
    Phoenix, AZ USA

  3. #3
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Re: VB Help


    if lstShopping.ListCount = 0 then
    msgbox "Removing nothing does nothing"
    else
    'your code here
    endif



    I wouldn't do this though. I'd be inclined to enable the cmdRemove button when you add the first item and disable when you remove the last item

    thanx/good luck,
    adam
    thanx/good luck

  4. #4
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Re: VB Help

    ahh, always do less than 1 vs. equal to 0. good call

    thanx/good luck,
    adam
    thanx/good luck

  5. #5
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: VB Help

    Yeah I have learned that the hard way before!

    Kris
    Software Engineer
    Phoenix, AZ USA

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured