Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I make calculations with one textbox like in the picture, I have tried to do that like this:

Example 1:
Input in textbox one = 1 + 1
Results in textbox two = 2

Example 2:
Input in textbox one = 3, 4, 5, 4
Results in textbox two = 4

Picture example:
https://image.winudf.com/v2/image/Y29tLmhpb3guTWVNZWRpTW9kZUNhbGN1bF9zY3JlZW5fMV8xNTM4MjU3MjMxXzAyOQ/screen-1.jpg?fakeurl=1&type=.jpg[^]

What I have tried:

'Example 1 code:

Dim tb1 as double
tb1 = val(textbox.text)

Rslttext = tb1

'Example 2 code:

Dim tb1 as double
tb1 = val(textbox.text)

Rslttext = math.mean(tb1)
Posted
Updated 28-Jul-20 1:13am

That's a lot more complicated than you might think.
But, it's been done a load of times, so try here: math / function / boolean /string expression evaluator[^]
Or even:
C#
DataTable dt = new DataTable();
object result = dt.Compute("12 * (8 - 3) / 2","");
 
Share this answer
 
The Val function converts a string from text characters to an actual numeric value. But it does not calculate expressions, you need to write the code to do that part. See Conversion.Val Method (Microsoft.VisualBasic) | Microsoft Docs[^].

[edit]
See also An expression evaluator written in VB.NET[^]
[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900