473,591 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need one little piece of code to allow me to find duplicate arrays

1 New Member
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 already entered. Any help would be greatly appreciated. This is what i have so far except the code to check for duplicate values:

Expand|Select|Wrap|Line Numbers
  1. Dim intarray() As Integer
  2. Dim intindex As Integer
  3. Dim intcount As Integer
  4. Dim intsearch As Integer
  5. Dim intlow As Integer, inthigh As Integer
  6. intlow = -32676
  7. inthigh = 32676
  8. ReDim intarray(intlow To inthigh)
  9.  
  10. For intindex = LBound(intarray) To UBound(intarray)
  11. Do
  12. intnumber = InputBox("Enter a number:", "Enter number")
  13. If intnumber < 1 Or intnumber > 99 Then
  14. MsgBox "Please enter numbers only between 1 and 99"
  15. End If
  16. intarray(intindex) = intnumber
  17. intcount = intcount + 1
  18. lstnums.AddItem intnumber
  19. Loop Until 'duplicate is found
  20. Next intindex
  21. lbldisplay.Caption = "Duplicate number after " & intcount & " times."
  22.  
  23. End Sub
Mar 31 '08 #1
2 2571
jg007
283 Contributor
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 already entered. Any help would be greatly appreciated.
what about doing a bubble / shell sort then running throught the values comparing them to the next one in the array, the only problem would be if you did not want the values sorted

here is a link for shell sort which can be ammended to sort text instead of numbers although for some reason it only seems to work once the array is at least 5 long

http://www.dreamincode.net/code/snippet857.htm
Mar 31 '08 #2
Killer42
8,435 Recognized Expert Expert
The sort seems a bit over the top, since it will have to comapre all the values at least once anyway.

Just do a nested loop. For example...

Expand|Select|Wrap|Line Numbers
  1. Dim I As Long, J As Long
  2. For I = 1 To SizeOfArray - 1
  3.   For J = I + 1 To SizeOfArray
  4.     If Array(I) = Array(J) Then
  5.       DuplicateFlag = True
  6.       Exit For
  7.     End If
  8.   Next
  9.   If DuplicateFlag Then Exit For
  10. Next
  11.  
This is just off the top of my head, don't take it as Gospel. :)
Apr 1 '08 #3

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

Similar topics

0
1900
by: lawrence | last post by:
Dear Peter, Do we know anyone else who writes PHP code? There is too much work to do, especially if Costin and I are going to join our software together. The easiest way for us to join our software together is through high level wrapper classes that take other classes for arguments. Costin and I could move toward joining the software one package at a time.
1
2670
by: JaNE | last post by:
Hello, I have made my cms... and is working, but have some, let me say "bugs"... And I don't know all reasons, please allow me slightly longer and most probably confusing post (that "confusing" is mainly becaose of my bad english, and that bad english is also reason why am I learning php that slow...). As first, what is problem: some users after succsesfull registration and login can not see "memeber_menu" and can not activly participate...
41
3936
by: Psykarrd | last post by:
I am trying to declare a string variable as an array of char's. the code looks like this. char name; then when i try to use the variable it dosn't work, however i am not sure you can use it the way i am trying to. Could some one please tell me what i am doing wrong, or another way of doing the same thing. i am trying to use the variable like this.
19
4083
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
31
2608
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant but it appears to work. using time, i measured it takes .041s to execute, which i admit isnt much. but, the problem is that this procedure will be called many, many times in my project (probably at least a few thousand times, if not more) so...
1
1348
by: amerar | last post by:
Hi All, Here is my situation: I have a form where the user can perform a number of tasks. One of these tasks is to enter a new record. The form has an 'onsubmit' property to validate the data if the users enters a new record. However, there is also a button to allow the user to 'duplicate' a stored record. In that case, I do not want to perform the entire validation since most of the data will be fetched from the database
15
4586
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
21
3188
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code (i.e. the get_hash function) is borrowed from various snippets I found on the net. Thee free function could probably need some love. I have been thinking about having a second linked list of all entries so that the cost of freeing is in proportion to...
0
3935
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
0
7934
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7870
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8225
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6639
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5400
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2378
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 we have to send another system
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.