Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

control array

Posted on 2000-05-02
11
Medium Priority
?
203 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

604 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