Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8945693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:18:34+00:00 2026-06-15T12:18:34+00:00

I have able to create a function that will perform Reverse Polish notation. The

  • 0

I have able to create a function that will perform Reverse Polish notation. The structure of the method is fine the two issues I am running into is how to grab the formula the user inputs in textBox1 and display the answer(formula = answer) on textBox2. I have assigned to textBox1 the variable rpnValue but it gives an error message A field initializer cannot reference the non-static field, method, or property 'modified_rpn.Form1.textBox1'. So once again how can I grab the formula the user inputs in textBox1 and display the answer(formula = answer) on the multiline `textBox2?

Code

namespace rpn
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string rpnValue = textBox1.Text; 

        private void RPNCalc(rpnValue)
        {
            Stack<int> stackCreated = new Stack<int>();
            try
            {
                var tokens = rpnValue.Replace("(", " ").Replace(")", " ")
                                     .Split().Where(s => !String.IsNullOrWhiteSpace(s));
                foreach (var t in tokens)
                {
                    try
                    {
                        stackCreated.Push(Convert.ToInt32(t));
                    }
                    catch
                    {
                        int store1 = stackCreated.Pop();
                        int store2 = stackCreated.Pop();
                        switch (t)
                        {
                            case "+": store2 += store1; break;
                            case "-": store2 -= store1; break;
                            case "*": store2 *= store1; break;
                            case "/": store2 /= store1; break;
                            case "%": store2 %= store1; break;
                            case "^": store2 = (int)Math.Pow(store1, store2); break; 
                            default: throw new Exception();
                        }
                        stackCreated.Push(store2);
                    }
                }

                if (stackCreated.Count != 1)
                    MessageBox.Show("Please check the input");
                else
                    textBox1.Text = stackCreated.Pop().ToString();

            }
            catch
            {
                MessageBox.Show("Please check the input");
            }

            textBox2.AppendText(rpnValue);
            textBox1.Clear();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            RPNCalc(textBox1, textBox2);
        }
    }
}

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:18:35+00:00Added an answer on June 15, 2026 at 12:18 pm

    You would need to move this line:

        string rpnValue = textBox1.Text; 
    

    inside a method or a function. You have it outside a method or function and you cannot do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Function constructors are able to create objects in javascript but I have a more
I have to create a field where I will be able to select between
For my program I am trying to create a function that will generate an
I am a beginner with MSBuild. So far I have been able to create
I have tried FBConnect for iPhone and am able to create/manage sessions and upload
I need to be able to create an id for a hyperlink. I have
I have the follwing code, I m able to create a drop down list
Suppose that I have two data types Foo and Bar. Foo has fields x
My goal is create a graph that will hide and show a series depending
My goal is to create an executable that will start a shadow copied application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.