# CALCULATOR DESIGN

• ### Question

•  Welcome

I design a calculator with specific features
I have
thirdproblems :-

First, do not place two tags attached, such as division, multiplication, addition and subtraction marks

Second, when the numbers are put together with the plus and division marks within a single text box, how do we get the output in another text box?

The third can not be divided by zero

Monday, April 23, 2018 3:18 AM

• Hi monemas,

Maybe you can look this example, I think it will helpful to you.

https://code.msdn.microsoft.com/windowsdesktop/VBNet-Calculator-08065b6b

Best Regards,

Cherry

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

• Marked as answer by Wednesday, April 25, 2018 4:11 AM
Monday, April 23, 2018 5:33 AM

### All replies

• Hi monemas,

Maybe you can look this example, I think it will helpful to you.

https://code.msdn.microsoft.com/windowsdesktop/VBNet-Calculator-08065b6b

Best Regards,

Cherry

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

• Marked as answer by Wednesday, April 25, 2018 4:11 AM
Monday, April 23, 2018 5:33 AM
• Having two signs in a row is not necessarily a problem.  Consider, for example, 5 plus negative 3; you'd write it "5+-3".

You probably have a "Total" or "Calculate" button that signals you to do the computation.  That's where you'd scan the input text to make sure it doesn't have any syntax errors.  That's also where you'd do the computation, and store it in a second box.

Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

Monday, April 23, 2018 5:39 AM
• Why do you think a string can perform math if you aren't using a library that performs math on strings?

It would be up to you to write code that can perform math on strings, not very simple.

Also see NCalc and try not designing things if there is no idea how to implement them. You should ask first IMO.

La vida loca

Monday, April 23, 2018 8:29 PM
• This all depends on your design. You can decide what the calculator does and how it does it. Very generally, there are two possible designs.

You could have an "=" button and then the formula is calculated when that button is pushed. So then you would need to process (parse) the formula. You might issue a message if there is a problem and then stop processing the formula.

Or you could process each key as it is typed. If you want help with that then you should post in the appropriate forum, probably one of the following:

• Windows Forms
• WPF
• UWP

The VB language does not have features for processing GUI messages, those are features of the relevant GUI library. If your process each key as it is typed then when you get an operator such as "+" or "-" then you take appropriate action. If an operator is typed right after another operator then that might be an error but you need to allow for negative numbers as has been said. Processing of an operator could include putting a result someplace such as a textbox.

Sam Hobbs
SimpleSamples.Info

Monday, April 23, 2018 10:50 PM
• Why do you think a string can perform math if you aren't using a library that performs math on strings?

C# can do math, we don't need a separate library to do math in C#.

Sam Hobbs
SimpleSamples.Info

Monday, April 23, 2018 10:53 PM
• Why do you think a string can perform math if you aren't using a library that performs math on strings?

C# can do math, we don't need a separate library to do math in C#.

Sam Hobbs
SimpleSamples.Info

VB.Net can do math too. However OP wants a string typed into a TextBox to perform math from what I can tell. That is altogether different.

La vida loca

Tuesday, April 24, 2018 1:19 AM
• However OP wants a string typed into a TextBox to perform math from what I can tell. That is altogether different.

Things like parentheses and functions can make things complicated. Variables can be complicated. If it is a simple matter of processing left-to-right, going just the one direction and with just numbers and operators and all operators/verbs/actions are one character, then that could be simple.

Theoretically parentheses could be supported with a stack by pushing onto the stack for a left parentheses and popping off the stack for a right parentheses and I believe I could figure that out but it might not be a beginner task.

Many developers would process parentheses using recursion but I try to avoid recursion. See Iteratively Processing Recursive Data, Such As Directories for an article about avoiding recursion.

Sam Hobbs
SimpleSamples.Info

Tuesday, April 24, 2018 3:51 AM