简体   繁体   English

搜索表带有x个参数

[英]Search table with x number of arguments

I'm trying to find a desired row index of a table(s). 我试图找到所需的表的行索引。 Difficulty is that I need to check multiple values found in the columns. 困难在于我需要检查在列中找到的多个值。

For example. 例如。

  • Table 1 has 1 unique column 表1具有1个唯一列
  • Table 2 has 2 columns to find a unique row 表2有2列来查找唯一行
  • Table 3 has 3 columns to find a unique row 表3有3列来查找唯一行

I would like my function to search the number of given arguments for the columns. 我希望我的函数搜索列的给定参数数。 But I don't quite know how. 但是我不太清楚。

I was thinking of passing a array {"Value1", "Value2", "Value3"} 我正在考虑传递一个数组{"Value1", "Value2", "Value3"}

But how can I check based on the number of arguments if the row matches? 但是,如何根据参数数量检查行是否匹配?

I was thinking somthing like this, but maybe there is a better solution to this problem? 我当时在想这样的事情,但是也许有更好的解决方案?

Private Function FindRow(ByVal StringArray As String()) As Integer
    Dim NumberOfArguments As Integer = oStringArray.Length
    Dim MatchesCount As Integer = 0

    For i = 0 as integer to rows.count

        For x = 0 as integer to columns.count
            For y = 0 as integer to NumberOfArguments
                If Row(i).Column(x).value = StringArray(y) Then
                    MatchesCount += 1
                End If
            Next
        Next

        If MatchesCount = NumberOfArguments Then
            FindRow = i
        End If
    Next
End Function
Private Function FindRowIndex(ParamArray values As String()) As Integer
    For i = 0 To rows.Count - 1
        Dim row = rows(i)
        Dim match = True

        For j = 0 To values.Length - 1
            If Not row(j).Equals(values(j)) Then
                match = False
                Exit For
            End If
        Next

        If match Then
            Return i
        Next
    Next

    Return -1
End Function

Because the method parameter is declared ParamArray , you can call it and pass multiple discrete values rather than having to create an array explicitly. 因为方法参数被声明为ParamArray ,所以您可以调用它并传递多个离散值,而不必显式创建一个数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM