Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 131,713 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,408 people online right now. Registration is fast and FREE... Join Now!




How Do I Find The Duplicate Values In Arrays

 
Reply to this topicStart new topic

How Do I Find The Duplicate Values In Arrays, Duplicate values in arrays in VB

Sergiu
post 1 Feb, 2005 - 01:15 AM
Post #1


New D.I.C Head

*
Joined: 31 Jan, 2005
Posts: 15



Thanked 1 times
My Contributions


I was wondering how I could do this project in VB 6.0. I have a form in which I enter numbers between 1 and 99 in an input box. The numbers have to be put in an array and then once a duplicate value has been entered the numbers entered before the duplicate value are displayed in a listbox. A message should then be displayed of how many numbers were entered before the duplicate value occured.
Whoever can help is my hero!!!!!!!!!!!!!!!!!!
AFI RULES!!!!!!!
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 1 Feb, 2005 - 02:56 AM
Post #2


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,895



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


This may seem lame but you have to iterate through every element in the array and check whether data contained in them is equal to the currently entered number through the Input-Box.

Do you need this in code?
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 1 Feb, 2005 - 02:58 AM
Post #3


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,895



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


do one thing....I just remembered the dream.in.code Rules.
"U cant help people in code unless they've tried themselves"
Give me the source code that takes values through Input-boxes...I'll then modify it...
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 1 Feb, 2005 - 06:12 AM
Post #4


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


Good show, born2c0de...you only have to worry about code like that when it's for homework, though. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Sergiu
post 1 Feb, 2005 - 07:59 AM
Post #5


New D.I.C Head

*
Joined: 31 Jan, 2005
Posts: 15



Thanked 1 times
My Contributions


Well this is how much I have done so far.
I sent it in an attachment.


Attached File(s)
Attached File  Unit16_DuplicateValues.frm ( 2.73k ) Number of downloads: 45
User is offlineProfile CardPM

Go to the top of the page

Sergiu
post 1 Feb, 2005 - 10:02 AM
Post #6


New D.I.C Head

*
Joined: 31 Jan, 2005
Posts: 15



Thanked 1 times
My Contributions


OMG I am so close.
I fell that this code should work but for some reason it doesn't. Someone please help me this is project is due tomorrow.
I changed the code to this:
Private Sub Command1_Click()
Dim uinput As Integer
uinput = InputBox("Enter numbers between 1 and 99 in the space provided.", "This is where you enter numbers.")
Dim nums(0 To 99) As Integer, Item As Integer, Item1 As Integer

If uinput < 1 Or uinput > 100 Then
Label1.Caption = ""
Else
Label1.Caption = "Current number: " & uinput
End If


For Item = LBound(nums) To UBound(nums) - 1
If nums(Item) = uinput Then
List1.Clear
For Item1 = LBound(nums) To UBound(nums)
List1.AddItem "Value # " & Item1 + 1 & vbTab & nums(Item1)
Next Item1
MsgBox "Value # " & Item + 1 & ", (" & uinput & ") is the same as value # " & UBound(nums) + 1 & ", (" & nums(UBound(nums)) & ")."
End If
Next Item

End Sub

Thanx to whoever.
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 1 Feb, 2005 - 10:13 AM
Post #7


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


I'm afraid I don't have a VB compiler at the office...what is the problem you are experiencing?
User is offlineProfile CardPM

Go to the top of the page

Sergiu
post 1 Feb, 2005 - 10:44 AM
Post #8


New D.I.C Head

*
Joined: 31 Jan, 2005
Posts: 15



Thanked 1 times
My Contributions


It just won't recognize the duplicate as a duplicate value and it wont display it in the list box. I've been working at it through the night and the frigging thing won't work.
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 1 Feb, 2005 - 11:20 AM
Post #9


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,895



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


ok...i got it right...but im in a hurry...i'll post the modified form real soon...just hope u have the patience...yu've made some very honest mistakes...remember that there are logical errors in your code...anyway just wait till i upload it....i'll let u know where u went wrong...till then...hang on...
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 5 Feb, 2005 - 06:02 AM
Post #10


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,895



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


Sorry...I really forgot that I hadn't posted the updated code here...

I've made a few changes to your code. Firstly I have stored the Numbers directly into the Variable instead of Inputbox() to Label to Variable.

Then I've cleaned up the loops a bit.
In your uploaded form the check for a duplicate number is done only at the end...however we need to ensure this check everywhere in the loop ensuring that the newly added number isnt compared with itself. That's why I've used the Outer For Boundary as Listbox.ListCount -2 to avoid comparing the newly added number.

Also I used the ListCount Function from the Listbox instead of the UBound() and LBound() as it looks much more cleaner and runs faster as well...Here's the modified form...it works....let me know if you have any more difficulties understanding how the code works.


Attached File(s)
Attached File  test.frm ( 2.57k ) Number of downloads: 31
User is offlineProfile CardPM

Go to the top of the page

tel0r
post 22 Feb, 2005 - 02:37 PM
Post #11


New D.I.C Head

Group Icon
Joined: 22 Feb, 2005
Posts: 27



Dream Kudos: 200
My Contributions


CODE

Dim x As Long, y As Long
x = InputBox("Add number between 0 and 100")
If x < 0 Or x > 100 Then Exit Sub
For y = 0 To List1.ListCount - 1
   If List1.List(y) = x Then MsgBox "Found in List!" ':Exit Sub ''uncomment to stop list entry
Next y
List1.AddItem x
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 22 Feb, 2005 - 07:12 PM
Post #12


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,895



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


yup...this will work as well...
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 09:43AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month