Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find difference in array

Status
Not open for further replies.

smurfhell

MIS
Nov 5, 2004
45
US
I'm not looking for a specific answer, but rather, just some clues to get me in the right direction. I have a single dimension array like myarray="1,1,1,0,1,1,1" or myarray="0,1,1,1,1,1,1,1" or even myarray="1,1,1,1,1,1,1".

I am looking for a way to search myarray for any different numbers. In my examples, the first two would find that 0<>1 whereas the third one is all 1's and 1=1.

Are there any commands that might lead me to solving this problem on my own?

Thanks for the suggestions.
 
Set a variable equal to the first element in the array, then just loop through the array until you find a different value. If you get through the entire array before a different value is met, you have an array of all the same values.

Code:
dim firstElement = arrayNum(0)
dim differentValue = "NONE"

For x = 0 to UBound(arrayNum)
   if (firstElement <> arrayNum(x) then
      differentValue = arrayNum(x)
      x = UBound(arrayNum);      
   end If
Next

if (differentValue <> "NONE") then 
  'do something if different value found
else
  'do something if different value not found
end if




<.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top