LISTBOX

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

listbox.add(k1 " ;" & _

k2 " ;" & _ etc

Is it possible to write a code that reflects all these integer(3,6,7,8,9,11) at ones?

 

Answer Wiki

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

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

or this:

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

You could use an array and the <a href=”http://msdn.microsoft.com/en-us/library/system.array.indexof.aspx”>IndexOf function</a>.

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

<pre> Dim myArray() As Integer = New Integer() {3, 6, 7, 8, 9, 11}

If Array.IndexOf(myArray, k1+k2+k3+k4+k5) <> -1 Then
listbox.add(…
End If</pre>

-CarlosDL

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    To be more emphatic, the condition in the original question will always evaluate to true, and thus it is useless.
    69,225 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following