473,233 Members | 3,106 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,233 software developers and data experts.

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

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)
  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."
  23. End Sub
Mar 31 '08 #1
2 2555
283 100+
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

Mar 31 '08 #2
8,435 Expert 8TB
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
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

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...
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...
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...
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...
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...
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...
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...
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...
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 ...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.