473,480 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ArrayList problem

32 New Member
Hi all,
I am using Array List to store values.I am using this code.
Expand|Select|Wrap|Line Numbers
  1. Public Class Recovery
  2.         Public nFilename As String
  3.         Public nLockedby As String
  4.         Public nActivityID As String
  5.  
  6.         Public Sub New(ByVal nfilename As String, ByVal nLockedby As String, ByVal nActivityid As String)
  7.             MyBase.New()
  8.             Me.nFilename = nfilename
  9.             Me.nLockedby = nLockedby
  10.             Me.nActivityID = nActivityid
  11.         End Sub
  12.  
  13.     End Class
  14. Public Shared Function GetPreviousStatus() As Boolean
  15.  'Dim sTemparray As New ArrayList  'Initialized separtely
  16.    If sTemparray.Contains(New Recovery(sFilename, sLockedby, sActivityid)) = False Then
  17.            sTemparray.Add(New Recovery(sFilename, sLockedby, sActivityid))
  18.     End If
  19. End Function
Here I want to the Filename to be unique in the list.But this code allows the duplicate filename to be stored in the list.How can I restrict this

Dana
Jun 14 '07 #1
2 1084
nateraaaa
663 Recognized Expert Contributor
Hi all,
I am using Array List to store values.I am using this code.
Expand|Select|Wrap|Line Numbers
  1. Public Class Recovery
  2.         Public nFilename As String
  3.         Public nLockedby As String
  4.         Public nActivityID As String
  5.  
  6.         Public Sub New(ByVal nfilename As String, ByVal nLockedby As String, ByVal nActivityid As String)
  7.             MyBase.New()
  8.             Me.nFilename = nfilename
  9.             Me.nLockedby = nLockedby
  10.             Me.nActivityID = nActivityid
  11.         End Sub
  12.  
  13.     End Class
  14. Public Shared Function GetPreviousStatus() As Boolean
  15.  'Dim sTemparray As New ArrayList  'Initialized separtely
  16.    If sTemparray.Contains(New Recovery(sFilename, sLockedby, sActivityid)) = False Then
  17.            sTemparray.Add(New Recovery(sFilename, sLockedby, sActivityid))
  18.     End If
  19. End Function
Here I want to the Filename to be unique in the list.But this code allows the duplicate filename to be stored in the list.How can I restrict this

Dana
Have a look at the following function I think it may help you

Expand|Select|Wrap|Line Numbers
  1. Public Function RemoveDups(ByVal items() As String, ByVal sort As Boolean) As String()
  2.         Dim noDups As ArrayList = New ArrayList
  3.         Dim i As Integer = 0
  4.         Do While (i < items.Length)
  5.             If Not noDups.Contains(items(i).Trim) Then
  6.                 noDups.Add(items(i).Trim)
  7.             End If
  8.             i = (i + 1)
  9.         Loop
  10.         If sort Then
  11.             noDups.Sort
  12.         End If
  13.         'sorts list alphabetically
  14.         Dim uniqueItems() As String
  15.         noDups.Count
  16.         noDups.CopyTo(uniqueItems)
  17.         Return uniqueItems
  18.     End Function
Nathan
Jun 14 '07 #2
danasegarane
32 New Member
Thanks Nathan,
It worked like a charm :)

Thanks once again
Dana
Jun 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
1800
by: Stephen | last post by:
Im trying to carry work out an else if clause in the below method but i'm having a lot of difficulty getting the correct code which allows me to check and see if an arraylist items has text in it...
4
1709
by: Hans De Schrijver | last post by:
I have a private ArrayList variable that holds objects of various types, though they're all derived from a common base class (User). What I would like to do is provide public accessor properties...
3
2837
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
9
5074
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...
9
1398
by: Leon | last post by:
I have a webform in which when the user press generate button the form generate six unique ramdon numbers, the user can also type these six numbers in manually in any order. however, the user can...
20
5943
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the...
0
1662
by: Grant Wickman | last post by:
Our team has just fixed a really nasty problem that appears to be caused by an obscure bug in the sort method of Arraylist and daisy-chained webservice stubs. We've fixed the bug so I'll not...
18
3220
by: Sam | last post by:
Hi All I'm planing to write an application which allows users dynamically add their points (say you can add upto 30,000) and then draw xy graph. Should I use an array for my coordinate point...
48
4402
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
8
4389
by: amazon | last post by:
I have a following structure that I am using with array list: Private Structure arrayliststruct Public Name As String Public value As String Public type As String End Structure and following...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7044
Oralloy
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,...
1
6739
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...
0
6929
tracyyun
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...
0
5337
agi2029
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,...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.