i need some example codes..

Recommended Answers

All 2 Replies

As you would count positive numbers...

Dim xCount as Integer, xList as Integer

xList = 0

For xCount = 0 To lstNumbers.Listcount - 1
    lstNumbers.ListIndex = xCount

    xList = Val(xList) + Val(lstNumbers.Text) ''Assuming that you have checked that it is only numbers...
Next xCount

After reading the original request, I wonder if the OP is really asking for: "How would I COUNT the NUMBER of negative numbers in a listbox" rather than "ADDING UP the total of the numbers in the list, regardless of whether they are positive or negative".

Might be something like this:

Dim xCount as Integer, xList as Integer
xList = 0
For xCount = 0 To lstNumbers.Listcount - 1
    lstNumbers.ListIndex = xCount
    if val(lstNumbers.text) < 0 then
        xList = xList + 1 ''Assuming that you have checked that it is only numbers...''
    endif
Next xCount
commented: True, but as always the op's are extremely vague, we have to second guess all.. :) +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.