Hi,
I am trying to write a program to convert an infix expression to a postfix expression.
My task is as follows:
To enter an expression, enter the numerical values in place of the variable names. Terminate the expression with the symbol $. For example, the expression ab+ would be entered as 1 3 + $
Create a button called READ SYMBOL. To enter the expression, enter each number or symbol and hit READ SYMBOL. When the last symbol is read, the program will display the value of the expression in a text box.
I have written my code and tried to run the program; however, I am not able to output a value for addition.
Code:
---------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Value1 As Integer
Dim Value2 As Integer
txtA.Text = CStr(Value1)
txtA.Text = CStr(Value2)
If IsNumeric(Element) Then
Push()
ElseIf Element = "+" Then
Pop()
Value2 = CInt(Element)
Pop()
Value1 = CInt(Element)
Element = CStr((Value1 + Value2))
Push()
ElseIf Element = "$" Then
Label1.Text = Element
End If
Label1.Text = Element
End Sub
End Class
---------
I probably added something that I shouldn't have somewhere down the line. I also made functions for both push and pop.
Any help would be appreciated!