Solved

control array

Posted on 2000-05-02
11
198 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
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

773 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