I have a 2-d array that the user enters tress species and diameter so it looks something like:
sm 10
rm 18
bf 12
sm10
sm10
rm18
and so on.. I need to be able to seach though my array and find all the duplicate values and know the number of each dupliate value so sm 10 would be 3 and rm 18 would be 2 and so on.. until the end of the array. I then will take that array and seach for a value in another array.. ( i think i may be able to do this second part) but its the finding dupliate values and number of them I'm havinig trouble with, I dont even know where to start. Thanks alot
2 3604
From the sounds of it Dawn123, you will have to attack this with a brute force method of looping from beginning to end comparing strings, which in vb is kind of slow. This example as you can see is for a single dimension array and to modify it for a two dimension array just add another outer loop... -
Option Explicit
-
-
Dim MyArray() As String
-
-
Private Sub Form_Load()
-
MyArray = Split("sm10,rm18,bf12,sm10,sm10,rm18", ",")
-
End Sub
-
-
Private Sub Command1_Click()
-
-
Dim StringToCount() As String
-
Dim CountOfString() As Integer
-
Dim OuterLoopCounter As Integer, InnerLoopCounter As Integer
-
Dim UpperBoundsOfArray As Integer, LowerBoundsOfArray As Integer
-
Dim UniqueStringCounter As Integer
-
Dim MessageString As String
-
-
LowerBoundsOfArray = LBound(MyArray)
-
UpperBoundsOfArray = UBound(MyArray)
-
-
For OuterLoopCounter = LowerBoundsOfArray To UpperBoundsOfArray
-
-
If IsStringInArray(MyArray(OuterLoopCounter), StringToCount()) = True Then
-
For InnerLoopCounter = LBound(StringToCount) To UBound(StringToCount)
-
If MyArray(OuterLoopCounter) = StringToCount(InnerLoopCounter) Then
-
CountOfString(InnerLoopCounter) = CountOfString(InnerLoopCounter) + 1
-
Exit For
-
End If
-
Next InnerLoopCounter
-
Else
-
ReDim Preserve StringToCount(UniqueStringCounter) As String
-
ReDim Preserve CountOfString(UniqueStringCounter) As Integer
-
StringToCount(UniqueStringCounter) = MyArray(OuterLoopCounter)
-
CountOfString(OuterLoopCounter) = 1
-
UniqueStringCounter = UniqueStringCounter + 1
-
End If
-
-
Next OuterLoopCounter
-
-
For InnerLoopCounter = LBound(StringToCount) To UBound(StringToCount)
-
MessageString = MessageString & StringToCount(InnerLoopCounter) & " = " & CountOfString(InnerLoopCounter) & vbNewLine
-
Next InnerLoopCounter
-
-
MsgBox MessageString
-
-
End Sub
-
-
Private Function IsStringInArray(StringToTest As String, ArrayToTestAgainst() As String) As Boolean
-
-
Dim ForLoopCounter As Integer
-
Dim UpperBoundsOfArray As Integer, LowerBoundsOfArray As Integer
-
-
'if you really want to know more about this test please read this thread
-
'http://www.tek-tips.com/viewthread.cfm?qid=1495917
-
If (Not ArrayToTestAgainst) = -1 Then Exit Function
-
-
LowerBoundsOfArray = LBound(ArrayToTestAgainst)
-
UpperBoundsOfArray = UBound(ArrayToTestAgainst)
-
-
For ForLoopCounter = LowerBoundsOfArray To UpperBoundsOfArray
-
If ArrayToTestAgainst(ForLoopCounter) = StringToTest Then
-
IsStringInArray = True
-
Exit For
-
End If
-
Next ForLoopCounter
-
-
End Function
-
Good Luck
Okay d123, recieved your pm and I did not split an array, I split a string into an array...
Good Luck
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Michelle |
last post by:
hi,
i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)
which i have sorted in alphabetical order, but i need to
identify duplicates...
|
by: quickcur |
last post by:
Suppose I have a function rand() that can generate one integer random
number between 0 and 100. Suppose also rand() is very expensive. What
is the fastest way to generate 10 different random number...
|
by: Leon |
last post by:
I need a program that generate 5 non-duplicates random number between 1-10
as string values store in an array.
Do anybody know of any good books or websites that explain how to generator
random...
|
by: vbportal |
last post by:
Hi,
I would like to add BitArrays to an ArrayList and then remove any duplicates
- can someone please help me forward. I seem to have (at leaset ;-) )2
problems/lack of understanding (see test...
|
by: JTreefrog |
last post by:
Hello - I've read a ton of stuff about deleting duplicate values in an array. They are all very useful - they just haven't addressed an array of objects.
Here's my array:
var sDat = ;
The...
| |
by: sqlservernewbie |
last post by:
Hi Everyone,
Here is a theoretical, and definition question for you.
In databases, we have:
Relation
|
by: cmdolcet69 |
last post by:
i need to find a way to look through my _ReadingArrayList3 and see if any number stored in the inarrayindex are duplicated. I need to first collect all the data and place it into the array, once the...
|
by: chandru8 |
last post by:
hi to all
iam using vb6.0 can any one tell me how to duplicate values in a array if possible i want to delete the duplicate values
its urgent
thanks
|
by: raphael001 |
last post by:
In my Visual Basic program I'm just trying to find duplicate values entered into an array from an inputbox, but i can't seem to get the coding right on the final part to check for duplicate values...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |