16226

PEMDAS Visual Basic [closed]

Question:

<strong>EDIT 2:</strong> *fixed some grammar and made it easier to understand.

I need help on building a PEMDAS application in vb.net. I want it to solve an inputted equation like this for example: 4 – 3(4 –2(6 – 3)) ÷ 2. I am trying to make it so that when input something into a text box and then click a button it will display the answer of that equation on a label. I first tried coding the section for looking for the parentheses, but it didn't work. I'm trying to make the program look for parentheses inside the equation and then depending on what the operator is inside of the parentheses, it will add, subtract, divide, or multiply the two numbers inside. My code is :

Public Class Form1 Private Property ValidChars As String Private Property Num2 As Object Private Property Num1 As Object Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ValidChars = ("()") If TextBox1.Text = ValidChars Then TextBox1.Text() = Num1 + Num2 End If End Sub End Class

Any help will be well appreciated.

Thanks, bye!

<strong>EDIT 1:</strong>

Hello I need help on building a PEMDAS application and I need help with it. I have a textbox and a button that I need to press on to get the answer and the answer is going to be on a label. I first did the parentheses which is the part that I didn't get working. What I need is a thing that could find the numbers in the parentheses and then if it shows a + , / , - , * , then it will do the thing but I need help with that. My code is : An Order of Operations program like this for example this : 4 – 3(4 –2(6 – 3)) ÷ 2 and the answer for it .

Public Class Form1 Private Property ValidChars As String Private Property Num2 As Object Private Property Num1 As Object Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ValidChars = ("()") If TextBox1.Text = ValidChars Then TextBox1.Text() = Num1 + Num2 End If End Sub End Class

Any help will be well appreciated.

Thanks Bye!

Answer1:

This should be what you're looking for. This built-in function has its limits especially if the expression involves trigonometric functions but this should be enough for your needs.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim answer = New DataTable().Compute(TextBox1.Text, Nothing) MsgBox(answer) Catch ex As Exception MsgBox("Syntax Error") End Try End Sub

If you want a more challenging approach, which I recommend you would, you can create your own algorithm to manipulate strings and get numbers within to solve the expression. String manipulation functions should be what you'll ever need such as Mid, Split, Contains, etc.

Recommend

  • Can you alter the output of %caller{0} in logback to mimic log4j %l specifier?
  • Macro to call a function
  • how to convert a unix timestamp into nsdate in iphone [duplicate]
  • Anonymous functions and Maps in Scala
  • interpolation in 3d computer graphics
  • iOS 8.3 - Metal, found nil while unwrapping an Optional Value
  • In BASH convert a string with . in float
  • Regex failing to match number and dash with letter (or space and letter)
  • Automatically change the position of objects when using different devices
  • GMP Bit shift doesn't work on negative numbers
  • Timer once a minute on the minute
  • Finding the number of elements less than or equal to k in a multiset
  • How to use arithmetic operators with SAS macro variables [duplicate]
  • Retrieving a double from a JTextArea while solving for X
  • How to use the resource module to measure the running time of a function?
  • Aptana 3 remove bundle (jquery)
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • Uncaught TypeError: $(…).select2 is not a function
  • RxJava debounce by arbitrary value
  • jQuery ready not fired after rails link_to is clicked
  • Very simple C++ DLL that can be called from .net
  • Yii2: Config params vs. const/define
  • Algorithm for a smudge tool?
  • Splitting given String into two variables - php
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • SSO with signing and signature validation doesn't work
  • How to model a transition system with SPIN
  • Build own AppleScript numerical error handling
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • Python: how to group similar lists together in a list of lists?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • Django query for large number of relationships
  • UserPrincipal.Current returns apppool on IIS
  • How to load view controller without button in storyboard?