Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest using a 2D array of "rules". When the user adds a rule, information such as rule type (equality, inequality) and the parameters to be tested will be entered into the array. Finally, when the check is being made, you can use the parameters inside an if..then statement inside a loop to test all elements of the array. If the rules are all combined with the AND opearator, then you can set a boolean variable to false and exit the loop. If you need more detail, or a code example, please post some trial code that I can work on.</p> <p>Edit with Code:</p> <p>I made a class that you can use for this purpose:</p> <pre><code>Option Explicit 'Class Parameters Dim pRules() As Variant 'note the variant data type Dim pCountRules As Long Private Sub class_initialize() pCountRules = 0 End Sub Public Sub AddRule(Parameter As Variant, Condition As Variant) 'note the variant data types If TypeName(Parameter) &lt;&gt; TypeName(Condition) Then 'one possible exception I can think of, handle this here Exit Sub End If If pCountRules = 0 Then pCountRules = 1 ReDim pRules(1 To 2, 1 To 1) pRules(1, 1) = Parameter pRules(2, 1) = Condition Else pCountRules = pCountRules + 1 ReDim Preserve pRules(1 To 2, 1 To pCountRules) pRules(1, pCountRules) = Parameter pRules(2, pCountRules) = Condition End If End Sub Public Sub ResetRules() Erase pRules pCountRules = 0 End Sub Public Function CheckRules() As Boolean Dim i As Integer If pCountRules = 0 Then CheckRules = True 'or false, depends on your logic Else CheckRules = True For i = 1 To pCountRules If pRules(1, i) &lt;&gt; pRules(2, i) Then CheckRules = False Exit For End If Next i End If End Function Private Sub Class_Terminate() Erase pRules End Sub </code></pre> <p>Note the use of variant data type. I avoid this when I can, you need heavy exception handling. If your data type is determined, then you can change this and include proper validation. I tested the class as follows:</p> <pre><code>Option Explicit Sub test() Dim Rules As clsRules Dim testarr(1 To 1, 1 To 3) As String Dim testparam(1 To 3) As String testarr(1, 1) = "a" testarr(1, 2) = "b" testarr(1, 3) = "c" testparam(1) = "a" testparam(2) = "b" testparam(3) = "c" 'values match Set Rules = New clsRules Rules.AddRule testarr(1, 1), testparam(1) Rules.AddRule testarr(1, 2), testparam(2) Rules.AddRule testarr(1, 3), testparam(3) 'will print true Debug.Print Rules.CheckRules 'change parameter so values do not match testparam(3) = "a" Rules.ResetRules Rules.AddRule testarr(1, 1), testparam(1) Rules.AddRule testarr(1, 2), testparam(2) Rules.AddRule testarr(1, 3), testparam(3) 'will print false Debug.Print Rules.CheckRules 'clean up Erase testarr Erase testparam Set Rules = Nothing End Sub </code></pre> <p>I hope this is useful for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload