PC Review


Reply
Thread Tools Rate Thread

Copy unique values to new array

 
 
Joep
Guest
Posts: n/a
 
      6th Aug 2004
Hi,

In VB.net I have an array which contains different values. For example:
array(0) = 2
array(1) = 2
array(2) = 2
array(3) = 3
array(4) = 3
array(5) = 6
array(6) = 6
array(7) = 4
array(8) = 4
array(9) = 4
I'd like to copy the unique values in this array to a new array, which
contains only these unique values. In this example arraySecond would be:
arraySecond(0) = 2
arraySecond(1) = 3
arraySecond(2) = 6
arraySecond(3) = 4

Can anyone help me with the code for creating this second array based on the
first? I cannot find a way to accomplish this.

Thanks in advance,
Joep


 
Reply With Quote
 
 
 
 
Telmo Sampaio
Guest
Posts: n/a
 
      6th Aug 2004
Joep,

mmm... that's pure logic stuff. I have an example below, but I would think of using an ArrayList instead of a regular array. Good luck!
//
Function GetArray(ByVal array() As Integer) As Integer()

Dim x, y, n, sa() As Integer

y = -1

n = 0

array.Sort(array)

For Each x In array

If x <> y Then

ReDim Preserve sa(n)

sa(n) = x

y = x

n += 1

End If

Next

Return sa

End Function

//

Telmo Sampaio

"Joep" <(E-Mail Removed)> wrote in message news:cf0aeg$69p$(E-Mail Removed)...
> Hi,
>
> In VB.net I have an array which contains different values. For example:
> array(0) = 2
> array(1) = 2
> array(2) = 2
> array(3) = 3
> array(4) = 3
> array(5) = 6
> array(6) = 6
> array(7) = 4
> array(8) = 4
> array(9) = 4
> I'd like to copy the unique values in this array to a new array, which
> contains only these unique values. In this example arraySecond would be:
> arraySecond(0) = 2
> arraySecond(1) = 3
> arraySecond(2) = 6
> arraySecond(3) = 4
>
> Can anyone help me with the code for creating this second array based on the
> first? I cannot find a way to accomplish this.
>
> Thanks in advance,
> Joep
>
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unique values in an array. Jerry Microsoft Excel Misc 2 15th Oct 2009 06:44 PM
unique values in an array th081th081@googlemail.com Microsoft Excel Programming 28 17th Jan 2008 09:18 PM
RE: Array formula for unique values =?Utf-8?B?RGFuIEhhdG9sYQ==?= Microsoft Excel Worksheet Functions 0 20th Jan 2007 02:11 AM
unique values to array Gary Keramidas Microsoft Excel Programming 4 6th Nov 2006 02:31 PM
Frequncy of unique values in array Fábio Coatis Microsoft Excel Programming 3 22nd Jul 2003 05:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:59 PM.