Solved

control array

Posted on 2000-05-02
11
196 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
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 9

Expert Comment

by:Dalin
Comment Utility
Use the Index to refer to the element
0
 

Expert Comment

by:baitz
Comment Utility
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
Comment Utility
For example,

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

Ok?!?
0
 

Author Comment

by:sshayevich
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:Dalin
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now