Hello, I'll be as clear as I can in this one. OK, here is what is going on: I'm kind of trying to create a programming language of some sort using a Console application. I have got most commands to work, but what I haven't got is the ability to perform addition of two numbers that are in the same line and display the result in the next line. Before I show you the "problematic" code, you better take a look at this so to better understand the rest of the code:
Dim input As String = Console.In.ReadLine Dim startIndex As Integer Dim output As String)
Here is the rest of the code:
If input.Contains("+") Then Try startIndex = input.IndexOf("+") Dim firstNum As Integer = input.Substring(startIndex - 1, 1) Dim secondNum As Integer = input.Substring(startIndex + 1, 1) output = firstNum + secondNum WriteLine("=> " & output) input = "" : GoTo repeat Catch ex As Exception WriteLine(ex.Message) input = "" : GoTo repeat End Try End If
The main problem with the code is that, while the program can perform addition of numbers with one digit, for numbers greater than nine it won't. I know this has to do with the specified length in the above code. The part with the problem is (startIndex - 1, 1), as well as (startIndex + 1, 1). I know I could just increase the length to greater values but, if I did this, I would then be required to type in a number with that number of digits no matter what. For example, if I set the length to 3, I would have to type in a three digit number in order for this to work, else it would throw an exception. Do you have any ideas regarding how I can solve this?
Edited 5 Years Ago by TechSupportGeek: n/a