textbox calculate expression

j0zef

New member
Joined
May 7, 2012
Messages
3
Programming Experience
5-10
Hello,

I have a question,

I want fill in a textbox for example 25 + 25

and in a label you can find the result 50

can anyone help me?
 
Here's one solution:

Dim op1 As Integer = 25
Dim op2 As Integer = 25
Dim ans As Integer = op1 + op2
Textbox1.Text = op1 & " + " & op2
Label1.Text = ans.ToString()
 
Here's one solution:

Dim op1 As Integer = 25
Dim op2 As Integer = 25
Dim ans As Integer = op1 + op2
Textbox1.Text = op1 & " + " & op2
Label1.Text = ans.ToString()

I think the idea was that the user would type the expression into the TextBox and the app would parse it and display the result.

If all you ever want to do is add two numbers then it's easy, but it becomes more and more difficult as you want to be able to use additional operators and longer expressions. Some the examples in the Google search I linked to will allow you to parse arbitrarily complex mathematical expressions.
 
Back
Top