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!
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!!!!!!!
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 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...
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
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.
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...
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) test.frm ( 2.57k )
Number of downloads: 31
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