Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.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
Vb.net 每个下一个循环到下一个循环的最大值_Vb.net - Fatal编程技术网

Vb.net 每个下一个循环到下一个循环的最大值

Vb.net 每个下一个循环到下一个循环的最大值,vb.net,Vb.net,很抱歉,如果这是一个非常基本的问题,但我的课本上说要修改btnGet_Click过程,使用For Each…Next语句,而不是For…Next语句。我不能让它正常工作,所以这里是每个…下一个循环的原始 Private Sub btnGet_Click(sender As Object, e As EventArgs) Handles btnGet.Click ' displays the highest commission and the ' number who were

很抱歉,如果这是一个非常基本的问题,但我的课本上说要修改btnGet_Click过程,使用For Each…Next语句,而不是For…Next语句。我不能让它正常工作,所以这里是每个…下一个循环的原始

 Private Sub btnGet_Click(sender As Object, e As EventArgs) Handles btnGet.Click
    ' displays the highest commission and the
    ' number who were paid that amount

    Dim intCommissions() As Integer = {2500, 3400, 1000,
                                       3400, 2500, 1000,
                                       2850, 3000, 2780, 1890}
    Dim intLastSub As Integer =
        intCommissions.GetUpperBound(0)
    Dim intHighest As Integer = intCommissions(0)
    Dim intSalesPeople As Integer = 1

    For intSub As Integer = 1 To intLastSub
        If intCommissions(intSub) = intHighest Then
            intSalesPeople += 1
        Else
            If intCommissions(intSub) > intHighest Then
                intHighest = intCommissions(intSub)
                intSalesPeople = 1
            End If
        End If
    Next intSub

    lblHighest.Text = intHighest.ToString("C0")
    lblSalespeople.Text = intSalesPeople.ToString
End Sub 

只需在
int
数组上运行for each:

    Dim intCommissions() As Integer = {2500, 3400, 1000,
                                3400, 2500, 1000,
                                2850, 3000, 2780, 1890}
    Dim intHighest As Integer = intCommissions(0)
    Dim intSalesPeople As Integer = 1

    For Each intCommission In intCommissions
        If intCommission = intHighest Then
            intSalesPeople += 1
        Else
            If intCommission > intHighest Then
                intHighest = intCommission
                intSalesPeople = 1
            End If
        End If
    Next

只需在
int
数组上运行for each:

    Dim intCommissions() As Integer = {2500, 3400, 1000,
                                3400, 2500, 1000,
                                2850, 3000, 2780, 1890}
    Dim intHighest As Integer = intCommissions(0)
    Dim intSalesPeople As Integer = 1

    For Each intCommission In intCommissions
        If intCommission = intHighest Then
            intSalesPeople += 1
        Else
            If intCommission > intHighest Then
                intHighest = intCommission
                intSalesPeople = 1
            End If
        End If
    Next

这不是你的书要求你做的,所以严格来说这不是你问题的答案,但是如果你想看看Linq

Dim intHighest = intCommissions.Max()
Dim intSalesPeople = intCommissions.Where(Function(x) x = intHighest ).Count()

lblHighest.Text = intHighest.ToString("C0")
lblSalespeople.Text intSalesPeople.ToString)

这不是你的书要求你做的,所以严格来说这不是你问题的答案,但是如果你想看看Linq

Dim intHighest = intCommissions.Max()
Dim intSalesPeople = intCommissions.Where(Function(x) x = intHighest ).Count()

lblHighest.Text = intHighest.ToString("C0")
lblSalespeople.Text intSalesPeople.ToString)

编辑您的帖子,向我们展示您对每个..尝试的
,并告诉我们哪些不起作用。编辑您的帖子,向我们展示您对每个..
尝试的
,并告诉我们哪些不起作用。