Solved

control array

Posted on 2000-05-02
11
201 Views
Last Modified: 2010-05-02
I have a control array(comboboxes), and I need to compare values of two comboboxes at run time after user inputs some values in comboboxes. How do I refer to these two controls?
0
Comment
Question by:sshayevich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 2769594
Use the Index to refer to the element
0
 

Expert Comment

by:baitz
ID: 2769607
Yes! You have to use the index to refer the array element. If you send me a e-mail with the code, I can reply...

0
 

Expert Comment

by:baitz
ID: 2769628
For example,

if combo(1).text = combo(2).text then
   beep
End If

Ok?!?
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:sshayevich
ID: 2769641
My user selects values from comboboxes.According to scenario two comboboxes can't have same values selected. So after they're done selecting i have to look at the values, and if there's 2 same values found, a prompts should be put up. So, I don't know which index to refer to.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2769647
Compare two members of the array:

If Combo1(0).Text = Combo1(1).Text Then
    'They match
End If


Or look at each control in the array:

Dim i As Long
For i = Combo1.LBound To Combo1.UBound
    Debug.Print Combo1(i).Text
Next
0
 
LVL 9

Expert Comment

by:Dalin
ID: 2769670
Example:

If Combo1(2).Text = Combo1(3).Text then
'some code
End If

In the combo's event, the index will pass to you to indicate which element you are in
Private Sub Combo1_Click(Index as Integer)
If Index= 0 then
      If Combo1(Index).Text = Combo1(1).Text then
         End If
    Else
      If Combo1(index).Text = Combo1(0).Text then
         End If
    End If

  End sub
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 100 total points
ID: 2769683
Private Sub Command1_Click()

Dim i As Long, j As Long
For i = Combo1.LBound To Combo1.UBound
    For j = i + 1 To Combo1.UBound
        If Combo1(i).Text = Combo1(j).Text Then
            MsgBox "Matched Values: " & Combo1(i).Text & " = " & Combo1(j).Text
            Exit Sub
        End If
    Next
Next

End Sub
0
 

Author Comment

by:sshayevich
ID: 2769788
I've tried this code before, and I get the msgbox"same values" no matter wether there is or there's no duplicate value found.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2769825
Make sure you are not indexing the same control. Use

Debug.Print i; j

just before

MsgBox ...

to confirm they are not equal.
0
 
LVL 4

Expert Comment

by:abaldwin
ID: 2769830
On another note.

Where are the list for the combo boxes getting their data.  Is it from a DB table?

One thing you could do is to put code in the lost focus event of the combo boxes and rebuild the list excluding any value selected.

Just a rough idea.

Andy
0
 

Author Comment

by:sshayevich
ID: 2770154
Thank you
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question