473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Checking for duplication in an array or delimited string

CJM
In an application I'm working the user has the opportunity to record the
despatching of one or more items with serial numbers.

For each item they despatch, they have to chose the serial no that they want
to despatch from a list of available ones. In many cases, these items will
be of the same time, so the dropdown of available serial no's may be the
same.

So now I need to check that the user hasnt picked the same serial no for two
items....

The serial no fields all have the same name, so when doing the server side
validation I'll be presented with a delimited string as a result. What is
the best way to make sure that none of these serial numbers are duplicated.
I havent thought of a specific solution yet, but I imagine you could use
InStr or Arrays to bully the result out, or perhaps enter the values into a
recordset and manipulate them that way; I havent got as far as figuring out
any kind of sultion yet, but I figured that someone on the NG will have
already thought of a quick & efficient approach - I reckon this must be a
reasonably common issue out there...

Thanks in advance

Cheers

--
cj*******@REMOVEMEyahoo.co.uk
[remove the obvious bits]
Jul 22 '05 #1
5 1717
"CJM" <cj*******@newsgroup.nospam> wrote in message
news:Ow*************@TK2MSFTNGP14.phx.gbl...
In an application I'm working the user has the opportunity to record the
despatching of one or more items with serial numbers.

For each item they despatch, they have to chose the serial no that they want to despatch from a list of available ones. In many cases, these items will
be of the same time, so the dropdown of available serial no's may be the
same.

So now I need to check that the user hasnt picked the same serial no for two items....

The serial no fields all have the same name, so when doing the server side
validation I'll be presented with a delimited string as a result. What is
the best way to make sure that none of these serial numbers are duplicated. I havent thought of a specific solution yet, but I imagine you could use
InStr or Arrays to bully the result out, or perhaps enter the values into a recordset and manipulate them that way; I havent got as far as figuring out any kind of sultion yet, but I figured that someone on the NG will have
already thought of a quick & efficient approach - I reckon this must be a
reasonably common issue out there...

Thanks in advance

Cheers

--
cj*******@REMOVEMEyahoo.co.uk
[remove the obvious bits]

The Dictionary object will work as each key must be unique.

Dim objDIC
Set objDIC = Server.CreateObject("Scripting.Dictionary")
Test to see if the serial number exists and, if not, add a serial number to
the Dictionary.

If Not objDic.Exists(serialnumber) The
objDIC.Add serialnumber, ""
Else
'* duplicate serialnumber processing
End If
Finally, when you're through, do some clean up:

Set objDIC = Nothing
Jul 22 '05 #2
split the delimited string to an array.

then either use the dictionary like mckirahan suggested, or just do this:

dim i, strCheck

strCheck = " "
for i = 0 to ubound(myarray) - 1
if instr(strCheck, " " & myarray[i] & "; ") = 0 then
strCheck = strCheck & myarray[i] & "; "
else
' duplicate serial
end if
next

of course with large arrays this is not performant at all... :-)
"CJM" <cj*******@newsgroup.nospam> wrote in message
news:Ow*************@TK2MSFTNGP14.phx.gbl...
In an application I'm working the user has the opportunity to record the
despatching of one or more items with serial numbers.

For each item they despatch, they have to chose the serial no that they
want to despatch from a list of available ones. In many cases, these items
will be of the same time, so the dropdown of available serial no's may be
the same.

So now I need to check that the user hasnt picked the same serial no for
two items....

The serial no fields all have the same name, so when doing the server side
validation I'll be presented with a delimited string as a result. What is
the best way to make sure that none of these serial numbers are
duplicated. I havent thought of a specific solution yet, but I imagine you
could use InStr or Arrays to bully the result out, or perhaps enter the
values into a recordset and manipulate them that way; I havent got as far
as figuring out any kind of sultion yet, but I figured that someone on the
NG will have already thought of a quick & efficient approach - I reckon
this must be a reasonably common issue out there...

Thanks in advance

Cheers

--
cj*******@REMOVEMEyahoo.co.uk
[remove the obvious bits]

Jul 22 '05 #3
CJM

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:1b********************@comcast.com...


The Dictionary object will work as each key must be unique.

Dim objDIC
Set objDIC = Server.CreateObject("Scripting.Dictionary")
Test to see if the serial number exists and, if not, add a serial number
to
the Dictionary.

If Not objDic.Exists(serialnumber) The
objDIC.Add serialnumber, ""
Else
'* duplicate serialnumber processing
End If


I did actually look at the dictionary object, but never came to a
conclusion, but this solution looks to be both efficient and effective...

Thanks
Jul 22 '05 #4
There are many ways that you could check for duplication each has its pros
and cons and the performance for each will vary with the number and type of
the data to be checked.

One is the dictionary object as mentioned.

If the list is very short then a "brute force" search (also already
mentioned) may have better performance than dictionary because there would
be no overhead for the dictionary object creation.

For longer lists you could build an array in sorted order and do a binary
search for duplicate values (look for "binary search" and "insertion sort"
algorithms).

If the key values are numeric and always in a restricted range then you
could also build an array where the key value or a simple derivative of the
key is the index. This approach would be neater with JScript because JScript
arrays are dynamic and sparse (only use memory for elements that have
values).

You could conceivably build a script object that would pick the "best"
method based on the number of elements in your original list.

--
--Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"CJM" <cj*******@newsgroup.nospam> wrote in message
news:Oj**************@TK2MSFTNGP15.phx.gbl...

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:1b********************@comcast.com...


The Dictionary object will work as each key must be unique.

Dim objDIC
Set objDIC = Server.CreateObject("Scripting.Dictionary")
Test to see if the serial number exists and, if not, add a serial number
to
the Dictionary.

If Not objDic.Exists(serialnumber) The
objDIC.Add serialnumber, ""
Else
'* duplicate serialnumber processing
End If


I did actually look at the dictionary object, but never came to a
conclusion, but this solution looks to be both efficient and effective...

Thanks

Jul 22 '05 #5
CJM

"Mark Schupp" <no******@email.net> wrote in message
news:OB**************@TK2MSFTNGP09.phx.gbl...
There are many ways that you could check for duplication each has its pros
and cons and the performance for each will vary with the number and type
of the data to be checked.

One is the dictionary object as mentioned.

If the list is very short then a "brute force" search (also already
mentioned) may have better performance than dictionary because there would
be no overhead for the dictionary object creation.

For longer lists you could build an array in sorted order and do a binary
search for duplicate values (look for "binary search" and "insertion sort"
algorithms).

If the key values are numeric and always in a restricted range then you
could also build an array where the key value or a simple derivative of
the key is the index. This approach would be neater with JScript because
JScript arrays are dynamic and sparse (only use memory for elements that
have values).

You could conceivably build a script object that would pick the "best"
method based on the number of elements in your original list.

--
--Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com


mark,

I figure that in the majority of cases the brute force approach would
technically be the quickest since we are dealing with v. small lists here.
However, I've opted for the dictionary approach, because a) the overhead is
not significant enough to affect this low-ish volume system, and b) I like
it...

Cheers

Chris
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Arne | last post by:
From: "Arne de Booij" <a_de_booij@hotmail.com> Subject: Comma delimited array into DB problems Date: 9. februar 2004 10:39 Hi, I have an asp page that takes input from a form on the previous...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
6
by: Deano | last post by:
I think my brain has short-circuited again :) Is this the quickest way to check for the existence of a given value in an array? e.g For i = 0 To rrst.RecordCount If myArray(i) =...
11
by: darrel | last post by:
let's say I have a string that can be any number of items comma delimited: 2, 4, 6, 12, 345 I want to check against those values in an if/then statement: if integer = any value in the...
33
by: Peace | last post by:
I am having trouble writing code to turn an array into a delimited string. Dim splitout As String splitout = Join(DataArray(rows, columns), " ") rows and columns are integers representing rows...
9
by: rodchar | last post by:
Hey all, what's the best way to get the contents of an array into a datagrid, edit the values, and then save edited values back into array format? thanks, rodchar
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
5
by: Dave Cullen | last post by:
I have a program that reads a delimited text file and splits the input string into string array elements: Dim Data(41) as String 'read semicolon delimited fields into string array Data =...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.