Hi everyone! For months now I've been reader of this forum and it's now time for me to register and start contributing. Well, my problem is basically with arrays and loops, in a calculator project..
What I'm trying to do is to write all operations in a line i.e: ( 2 + 1 - 3 + 2 )
Then, when pressing the Equal button, it automatically finds the operators and solves the operation. For this I'm trying to use a loop,so that if indexof("+") is not -1, then it founds the operator, then susbstring the string from the operator to the back, and it0s stored into an array for then executing the normal arithmetic functions.
Here's the code so you can understand what I'm trying to explain
Private Sub btnIgualPrueba_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIgualPrueba.Click Dim i As Integer = 0 While Not txtOperaciones.Text.IndexOf("-") = -1 Resultado_Resta(i) = txtOperaciones.Text.Substring(0, txtOperaciones.Text.IndexOf("-")) i = i + 1 End While End Sub
There is offcourse a global array dimensioned earlier, but the problem lies in the substring method, where at debugging time, it ejects an error. It's the following:
IndexOutOfRangeException was handled.
Index was outside the bounds of the array
The issue here is that if I make the same code but whithout a loop or array, it works i.e: an if desicion structure..
Could somebody please help me? It's driving me nuts!