Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 用于在数组中搜索多个条件的函数_Arrays_Visual Studio_Search - Fatal编程技术网

Arrays 用于在数组中搜索多个条件的函数

Arrays 用于在数组中搜索多个条件的函数,arrays,visual-studio,search,Arrays,Visual Studio,Search,我只包括这个问题和我的部分解决办法。这个问题来自我的第一节编程课,所以请温柔一点 编写一个函数过程,当属性满足搜索条件时,返回propListBox中属性的索引。此函数稍后将由Search和SearchNext按钮的事件处理程序调用 使用以下步骤。该功能将用于实现要求12和13 第一个参数是搜索将从属性列表中开始的索引。第二个参数是卧室数量的搜索标准,第三个参数是浴室数量的搜索标准,第四个参数是状态的搜索标准。若0作为卧室/浴室的参数传递,则表示用户未指定卧室/浴室的搜索条件。若并没有任何内容作

我只包括这个问题和我的部分解决办法。这个问题来自我的第一节编程课,所以请温柔一点

编写一个函数过程,当属性满足搜索条件时,返回propListBox中属性的索引。此函数稍后将由Search和SearchNext按钮的事件处理程序调用

使用以下步骤。该功能将用于实现要求12和13

第一个参数是搜索将从属性列表中开始的索引。第二个参数是卧室数量的搜索标准,第三个参数是浴室数量的搜索标准,第四个参数是状态的搜索标准。若0作为卧室/浴室的参数传递,则表示用户未指定卧室/浴室的搜索条件。若并没有任何内容作为state的参数传递,那个就意味着用户并没有为state指定搜索条件

如果有多个条件,则应找到满足所有条件的属性。例如,如果startIndex的值为“0”,意味着您将从第一个属性开始搜索,如果卧室的参数为3,浴室的参数为3,则满足这两个条件的第一个属性是地址为“佛罗里达州奥兰多弗恩大道1314号32814”的属性

使用循环结构遍历每个属性,并将卧室、浴室和属性状态与传递给函数的参数进行比较。请注意,有关属性的信息存储在nbeds、NBATH和states数组中

属性搜索应从startIndex开始,并在找到满足所有条件的第一个属性时停止

此函数应在找到的属性的propListBox中返回索引。如果未找到,函数将返回-1

-------下面是我的代码------

  Private Function SearchForm(ByVal startIndex As Integer, 
  ByVal bedroom As Integer, 
  ByVal bathroom As Integer, 
  ByVal propState As String) As Integer

  Dim propFound As Integer
    Dim highIndex As Integer = propListBox.Items.Count - 1

    For propIndex As Integer = propListBox.SelectedIndex To highIndex

        If nBeds(propIndex) = bedroom Or bedroom = 0 Then
            If nBaths(propIndex) = bathroom Or bathroom = 0 Then
                If states(propIndex) = propState Or propState = String.Empty Then
                    propListBox.SelectedIndex = propIndex
                End If
            End If



        Else : MsgBox("Not Found")
        End If
    Next propIndex

    Return propFound
End Function

您是如何实现这两部分要求的?属性搜索应从startIndex开始,并在找到满足所有条件的第一个属性时停止。还有,您如何设置和返回匹配的索引?我不确定。if语句系列是否是检查这些条件的可行方法?我在数组方面遇到了很多麻烦,这就是我来这里的原因。是的,我认为你的一系列嵌套If语句是找到匹配项的好方法。循环当前从何处开始?…startIndex参数是否在代码中的任何地方使用?找到匹配项后,如何设置propFound变量并停止循环?它是否像返回propFound=ProIndex.selectedindex那样简单?基本上,但您只需在循环内使用propFound=ProIndex设置它,然后使用Exit For退出循环。此外,还需要将propFound设置为初始值-1,Dim propFound设置为Integer=-1。