vb.net, check array elements?
-
I need to check all element of an array to see if all are equal to 1 or 'T' then do something. how can i do this?
My first guess would be to iterate over the array and check the values, but of course that may be to simple for you to figure out.
I know the language. I've read a book. - _Madmatt
-
My first guess would be to iterate over the array and check the values, but of course that may be to simple for you to figure out.
I know the language. I've read a book. - _Madmatt
loop cant help because, may be I'm missing something for i=0 to array.length-1 if array(0) = 1 then check = true else check = false end if next this doent work for me because if the last element is 1 then the check(boolean variable)becomes true while it is possible that other elements for example first one is not equal to 1. but I need to make sure are all of them (all elements) are equal to 1 or not. Help please
-
loop cant help because, may be I'm missing something for i=0 to array.length-1 if array(0) = 1 then check = true else check = false end if next this doent work for me because if the last element is 1 then the check(boolean variable)becomes true while it is possible that other elements for example first one is not equal to 1. but I need to make sure are all of them (all elements) are equal to 1 or not. Help please
golisarmi wrote:
may be I'm missing something
Yes, you are. This is a good exercise to weed out the pretenders from the performers. Which are you?
I know the language. I've read a book. - _Madmatt
-
golisarmi wrote:
may be I'm missing something
Yes, you are. This is a good exercise to weed out the pretenders from the performers. Which are you?
I know the language. I've read a book. - _Madmatt
-
loop cant help because, may be I'm missing something for i=0 to array.length-1 if array(0) = 1 then check = true else check = false end if next this doent work for me because if the last element is 1 then the check(boolean variable)becomes true while it is possible that other elements for example first one is not equal to 1. but I need to make sure are all of them (all elements) are equal to 1 or not. Help please
You should probably encapsulate this into a function and return false for the first one that does not match and return true if you get to the end of the array without finding one that does not match. Incidentally, if you are using .NET 3.5, the built in All extension method from LINQ will do just that.
-
are you here to help people, specially beginners or to blame them. if you don’t know or don't want to say please don’t annoy them. Anybody else could help?
We are here to help, not give you everything. This is a very simple exercise in logic, don't get upset if you are not up to the task.
golisarmi wrote:
or to blame them
Read the previous posts carefully, there is no blame being assigned You are still new here so I would hold the attitude if I where you.
I know the language. I've read a book. - _Madmatt
-
You should probably encapsulate this into a function and return false for the first one that does not match and return true if you get to the end of the array without finding one that does not match. Incidentally, if you are using .NET 3.5, the built in All extension method from LINQ will do just that.
-
loop cant help because, may be I'm missing something for i=0 to array.length-1 if array(0) = 1 then check = true else check = false end if next this doent work for me because if the last element is 1 then the check(boolean variable)becomes true while it is possible that other elements for example first one is not equal to 1. but I need to make sure are all of them (all elements) are equal to 1 or not. Help please
check=true for i=0 to array.length-1 if array(0) <> 1 then check = false exit for end if next
-
check=true for i=0 to array.length-1 if array(0) <> 1 then check = false exit for end if next
I think this should work. If it doesn't, reply me back.. for i=0 to array.length-1 if array(i) = 1 then check = true else check = false end if next