on error goto err1:
list1="AAA"......ERR1:
msgbox "你要的项目不存在 ~~~~"

解决方案 »

  1.   

    List1.ListCount 可得到List1共有几个item

    For i = 0 To List1.ListCount - 1
        If List1.List(i) = "aaa" Then
            Exit For
        End
    Next
    If i >= List1.ListCount Then
        msgbox "你要的aaa项目不存在 ~~~~"
    End If
      

  2.   

    List1.ListCount 返回共有多少个。-1表示一个都没有。
    如:5 表示有0-4个item项。
      

  3.   

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const LB_FINDSTRINGEXACT = &H1A2Private Sub Command1_Click()
        Dim lret As Long
        Dim fnd_str As String
        
        fnd_str = "test"
        
        lret = SendMessage(List1.hwnd, LB_FINDSTRINGEXACT, -1, ByVal fnd_str)
        MsgBox lret
    End Sub
      

  4.   

    Private Sub Command1_Click()
    MsgBox existitem(List1, "66")
    End SubPrivate Sub Form_Load()
    List1.AddItem "55"
    List1.AddItem "66"
    End SubFunction existitem(lst As ListBox, str As String) As Boolean
    Dim i
    For i = 0 To lst.ListCount
    If lst.List(i) = str Then
    existitem = True
    Exit Function
    Else
    existitem = False
    Exit Function
    End If
    Next i
    End Function