0

我的代码没有在 AnswerText.Text 中显示文本是否有原因?

    Dim EquationValues() As String

    ' Split the array into a string array based on blank spaces
    EquationValues = DisplayTextBox.Text.Split(" "c)

    ' Declaring an integer as a counter for the loop
    Dim LoopCounter As Integer = 0

        ' Setting a for loop on the array and performing the operations
    For LoopCounter = 0 To EquationValues.Length - 1
        If EquationValues(LoopCounter) = "/" Then
            AnswerTextBox.Text = EquationValues(LoopCounter - 1) / EquationValues(LoopCounter + 1)
        End If

        If EquationValues(LoopCounter) = "*" Then
            AnswerTextBox.Text = EquationValues(LoopCounter - 1) * EquationValues(LoopCounter + 1)
        End If
    Next
4

1 回答 1

0

EquationValues 是一个数组,检查长度不是我认为您正在寻找的。您正在寻找计数...数组中的索引数...尝试

For LoopCounter = 0 To EquationValues.Count - 1

我回答了您之前关于字符串解析数学方程的问题(使用 vb 将字符串解析为方程)。该示例处理了 * 和 /,也许这可能对您有用。

祝你好运 :)

于 2013-02-17T02:05:15.053 回答