0

当我输入一个名字时,我做了一个循环来显示余额,但是当我第二次尝试这样做时。它不返回另一个输出(消息框)。如何结束/重新启动循环?

Public Class Form1
    Dim intMax_Subscript As Integer = 7
    Dim arrayNames(intMax_Subscript) As String
    Dim arrayBalance(intMax_Subscript) As Double
    Dim found As Boolean
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)    Handles MyBase.Load
        CBO1.Items.Add("John One")
        arrayNames(0) = CStr(CBO1.Items(0))
        CBO1.Items.Add("Jack Two")
        arrayNames(1) = CStr(CBO1.Items(1))
        CBO1.Items.Add("John Three")
        arrayNames(2) = CStr(CBO1.Items(2))
        CBO1.Items.Add("Jack Four")
        arrayNames(3) = CStr(CBO1.Items(3))
        CBO1.Items.Add("John Five")
        arrayNames(4) = CStr(CBO1.Items(4))
        CBO1.Items.Add("Jack Six")
        arrayNames(5) = CStr(CBO1.Items(5))
        CBO1.Items.Add("John Seven")
        arrayNames(6) = CStr(CBO1.Items(6))
        CBO1.Items.Add("Jack Eight")
        arrayNames(7) = CStr(CBO1.Items(7))


    CBO2.Items.Add("235.50")
    arrayBalance(0) = CDbl(CBO2.Items(0))
    CBO2.Items.Add("78943.98")
    arrayBalance(1) = CDbl(CBO2.Items(1))
    CBO2.Items.Add("230781.10")
    arrayBalance(2) = CDbl(CBO2.Items(2))
    CBO2.Items.Add("78362.00")
    arrayBalance(3) = CDbl(CBO2.Items(3))
    CBO2.Items.Add("12097.20")
    arrayBalance(4) = CDbl(CBO2.Items(4))
    CBO2.Items.Add("89267.34")
    arrayBalance(5) = CDbl(CBO2.Items(5))
    CBO2.Items.Add("34959.06")
    arrayBalance(6) = CDbl(CBO2.Items(6))
    CBO2.Items.Add("559284.50")
    arrayBalance(7) = CDbl(CBO2.Items(7))
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBalance.Click
    Dim input As String = InputBox("Input a name")
    Dim intcount As Integer = -1
    Dim intSubscript As Integer = 0


    Do While Not found And intcount < arrayNames.Length
        If arrayNames(intSubscript) = input Then
            found = True
            MessageBox.Show("The balance of " & input & "'s is " & arrayBalance(intSubscript))
            intSubscript = 0
            intcount = -1
        End If
        intSubscript += 1
    Loop
    If Not arrayNames.Contains(input) Then
        MessageBox.Show("Error: Name not found.")
    End If
End Sub
4

2 回答 2

1

You Need to reset the found to false after showing message box

If Not arrayNames.Contains(input) Then
MessageBox.Show("Error: Name not found.")
found = False
End If
于 2013-07-20T23:25:32.043 回答
1

你根本不需要'found'变量

Do While intcount < arrayNames.Length

    If arrayNames(intSubscript) = input Then
        MessageBox.Show("The balance of " & input & "'s is " & arrayBalance(intSubscript))
        intSubscript = 0
        Exit Do       
    End If
    intSubscript += 1

Loop
于 2013-07-21T00:00:21.953 回答