## Listbox in VB.NET

110 pts.
Tags:
VB.NET
VB.NET 2005
VB.NET 2008
I load list box with file data of 5 elements (k2,k2,k3,k4,k5) with up to 10000 results. I get the sum of these elements to be some integer (3,6,7,8,9,11). I write a code to eliminate some results like this:
```If (k1+k2+k3+k4+k5) <> 3 or

(k1+k2+k3+k4+k5) <> 6 or

If (k1+k2+k3+k4+k5) <> 7 or

(k1+k2+k3+k4+k5) <> 8 or

If (k1+k2+k3+k4+k5) <> 9 or

(k1+k2+k3+k4+k5) <> 11  then

k2 " ;" & _ etc```
Is it possible to write a code that reflects all these integer (3,6,7,8,9,11) at ones?

Thanks. We'll let you know when a new response is added.

First, I would like to bring to your attention the fact that when using OR conditions the final result will be true if at least one of the conditions is met (all other conditions don’t even need to be evaluated).

If you were doing something like this

```If (k1+k2+k3+k4+k5) <b><> 3 AND
(k1+k2+k3+k4+k5) <b><> 6 AND
(k1+k2+k3+k4+k5) <b><> 7 AND```

or this:

```If (k1+k2+k3+k4+k5) <b>= 3 OR
(k1+k2+k3+k4+k5) <b>= 6 OR
(k1+k2+k3+k4+k5) <b>= 7 OR```

You could use an array and the IndexOf function.

Something like this (you might need to change the “<> -1” to “= -1” below):

```Dim myArray() As Integer = New Integer() {3, 6, 7, 8, 9, 11}
...
If Array.IndexOf(myArray, k1+k2+k3+k4+k5) <> -1 Then
End If```

-CarlosDL