Get the return of a listbox

Posted on 2009-12-21
Last Modified: 2012-05-08
I am try9ing to see if a list box retuns anything, so that I can send a message tot he user that nothing was found.

I have tried theses
lbPers.items.counts  = 0
lbPers.items = 0
lbpers.itmes.counts = ""

If txtSearch.Text = "" Then

            RegisterClientScriptBlock("showMessage", "<script language=""JavaScript""> alert('Type in a Personnel Name First.'); </script>")


            sql = "Select Distinct strSSN, strName + '|' + Substring(strSSN, 6,9) from tblPermTask where strname like '" & Name & "%' " _

                & "Order by strName + '|' + Substring(strSSN, 6,9), strSSN"


            lbPers.Items.Add(New ListItem("Click Person to Add", "0"))

            buildDD(sql, lbSoldier)

        End If

        If lbPers.Items = 0 Then

            RegisterClientScriptBlock("showMessage", "<script language=""JavaScript""> alert('Personnel does not currently have any Issues.'); </script>")

        End If

        txtSearch.Text = ""

Open in new window

Question by:kdeutsch
    LVL 7

    Expert Comment

    Use the following condition..,

    lbPers.items IS NULL

    Author Comment

    Still using 1.1 and IS NULL or ISNULL of DBNULL are all incorrect and give blue underlines, never been able to solve that one.
    LVL 52

    Accepted Solution

    Well, looking at your code, testing for zero items won't work anyway because you are always forcing a fixed initial value (unless your buildDD method is clearing it again), so you should actually be testing:

        If lbPers.Items.Count == 1 Then        '// This indicates that there is nothing but the fixed initial value
    LVL 7

    Expert Comment

    You can use lbPers.Items = null instead.

    Author Comment

    Ok the == did not work for me but the follwoing did
    If lbPers.Items.Count <= 1 Then

    You got me think that my count really starts at 2 because I add in the click even to check that they picked on a person.
    LVL 52

    Expert Comment

    by:Carl Tawn
    Ah yes, sorry, should have been a single =.     Put it down to a bit of C# to VB cross-over :o)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now