在vb.net中退出不会退出

时间:2016-06-08 18:22:00

标签: vb.net

我有这些for循环:

For x = search_phone.Length To 0 Step -1
                    For m = 1 To number_call_costs
                        If search_phone.Substring(0, x) = call_costs_data(m, 2) Then
                            match = True

                            customer_cost = callcost_lookup("sequence", call_costs_data(m, 1), customer_sequence, "cost")
                            customer_connection = callcost_lookup("sequence", call_costs_data(m, 1), customer_sequence, "connection")
                            description = call_costs_data(m, 3)
                            MsgBox(call_costs_data(m, 3))
                            Exit For
                            Exit For
                        End If
                    Next
                Next

我正在测试的数据是:

search_phone = '101'
call_costs_data(m, 2) = one row is '1' and another row is '101'

它在循环中匹配search_phone101但它没有退出,因为它再次匹配到1

1 个答案:

答案 0 :(得分:2)

第二个出口无法到达,所以请尝试这样:

For x As Integer = search_phone.Length To 0 Step -1
  match = False
  For m As Integer = 1 To number_call_costs
    If search_phone.Substring(0, x) = call_costs_data(m, 2) Then
      match = True
      '// code...
      Exit For
    End If
  Next
  If match Then
    Exit For
  End If
Next