检查是否8组合框包含匹配彼此不包括空值 [英] Check to see if 8 comboboxes contain values that match one another excluding null

查看:216
本文介绍了检查是否8组合框包含匹配彼此不包括空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查,看看是否有我的8组合框相互匹配一次全部(当然不包括空值,因为它们都是空的形式加载时)?目前,我只知道如何做到这一点对当前和下一个。在那里有一个匹配的情况下,我想清除所有其他组合框除了一个焦点的值,即 currentDropDown

低于code:

 私人小组的Form_Load()
cboOption2.Enabled =假
cboOption3.Enabled =假
cboOption4.Enabled =假
cboOption6.Enabled =假
cboOption7.Enabled =假
cboOption8.Enabled =假
cboOption1.Value = NULL
cboOption2.Value = NULL
cboOption3.Value = NULL
cboOption4.Value = NULL
cboOption5.Value = NULL
cboOption6.Value = NULL
cboOption7.Value = NULL
cboOption8.Value = NULL
结束小组

子r总(currentDropDown,nextDropDown)
如果(currentDropDown.Value = nextDropDown.Value)然后
    MSGBOX你不能选择两次相同的值。
    currentDropDown.Value = NULL
结束如果
结束小组

私人小组cboOption1_Change()
呼叫r总(cboOption1,cboOption2)
结束小组

私人小组cboOption2_Change()
呼叫r总(cboOption2,cboOption3)
结束小组

私人小组cboOption3_Change()
呼叫r总(cboOption3,cboOption4)
结束小组

私人小组cboOption4_Change()
呼叫r总(cboOption4,cboOption5)
结束小组

私人小组cboOption5_Change()
呼叫r总(cboOption5,cboOption6)
结束小组

私人小组cboOption6_Change()
呼叫r总(cboOption6,cboOption7)
结束小组

私人小组cboOption7_Change()
呼叫r总(cboOption7,cboOption8)
结束小组

私人小组cboOption8_Change()
呼叫r总(cboOption8,cboOption8)
结束小组
 

解决方案

您需要通过组合框的收集循环,当前所选的值检查别人。

 子校验值(BYVAL currCombobox作为组合框)
昏暗的CTL作为对照,中巴作为组合框
    对于每个CTL在Me.Controls
        如果ctl.ControlType = acComboBox然后
            设置中巴= CTL
            如果(currCombobox.Value = cmb.Value)和(非currCombobox是CMB)然后
                MSGBOX无法选择它的两倍! &放大器; VBCR和放大器; VBCR和放大器; _
                        currCombobox.Name和放大器; =&安培; cmb.Name
            结束如果
        结束如果
    接下来CTL
设置CTL =什么

结束小组
 

用法:

 私人小组CombBox30_Change()
校验值CombBox30
结束小组
 

How do I check to see if any of my 8 comboboxes match one another all at once (excluding null values of course, because they are all null when the form loads)? At the moment I have only figured out how to do it for the current and next one. In the case where there is a match, I want to clear the values of all the other comboboxes apart from the one in focus i.e. currentDropDown.

Code below:

Private Sub Form_Load()
cboOption2.Enabled = False
cboOption3.Enabled = False
cboOption4.Enabled = False
cboOption6.Enabled = False
cboOption7.Enabled = False
cboOption8.Enabled = False   
cboOption1.Value = Null
cboOption2.Value = Null
cboOption3.Value = Null
cboOption4.Value = Null
cboOption5.Value = Null
cboOption6.Value = Null
cboOption7.Value = Null
cboOption8.Value = Null  
End Sub

Sub rTotal(currentDropDown, nextDropDown)
If (currentDropDown.Value = nextDropDown.Value) Then
    MsgBox "You cannot select the same value twice."
    currentDropDown.Value = Null
End If
End Sub

Private Sub cboOption1_Change()
Call rTotal(cboOption1, cboOption2)
End Sub

Private Sub cboOption2_Change()
Call rTotal(cboOption2, cboOption3)
End Sub

Private Sub cboOption3_Change()
Call rTotal(cboOption3, cboOption4)
End Sub

Private Sub cboOption4_Change()
Call rTotal(cboOption4, cboOption5)
End Sub

Private Sub cboOption5_Change()
Call rTotal(cboOption5, cboOption6)
End Sub

Private Sub cboOption6_Change()
Call rTotal(cboOption6, cboOption7)
End Sub

Private Sub cboOption7_Change()
Call rTotal(cboOption7, cboOption8)
End Sub

Private Sub cboOption8_Change()
Call rTotal(cboOption8, cboOption8)
End Sub

解决方案

You need to loop through the collection of comboboxes and check currently selected value to the others.

Sub CheckValue(ByVal currCombobox As ComboBox)
Dim ctl As Control, cmb As ComboBox
    For Each ctl In Me.Controls
        If ctl.ControlType = acComboBox Then
            Set cmb = ctl
            If (currCombobox.Value = cmb.Value) And (Not currCombobox Is cmb) Then
                MsgBox "Cannot select it twice!" & vbcr & vbcr & _
                        currCombobox.Name & " = " &  cmb.Name
            End If
        End If
    Next ctl
Set ctl = Nothing

End Sub

usage:

Private Sub CombBox30_Change()
CheckValue CombBox30
End Sub

这篇关于检查是否8组合框包含匹配彼此不包括空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆