c# - Read textbox and assign input to variable in another class -
I have tried to go through similar questions and answers about this subject, but I have a solution Or to understand).
On Form 1, I have three text boxes that will get user input. In a different class I have a way of using input from those text boxes.
Form1.cs only have text boxes and some buttons. The method in the other class is using
system; Using System.Collections.Generic; Using System.Linq; System usage threading. Task; Using System.Windows.Forms; Name Location RealEstateApp {Public Class RealEstateApp: Form 1 {/// & lt; Summary & gt; Main entry point for the application /// & lt; / Summary & gt; [STAThread] Public static zero Main () {Application.EnableVisualStyles (); Application.SetCompatibleTextRenderingDefault (wrong); Application.Run (New Form 1 ()); Const. Double RENTAL_AMOUNT = 1000.00; Real Estate Investing Investment 1 = New Real Estate Investment (2004, 150000, "65th Street"); Invest1.MonthlyExpense = GetExpenses (); invest1.IncomeFromRent = RENTAL_AMOUNT; invest1.DetermineMonthlyEarnings ()); Real Estate Investment Investments 2 = New Real Estate Investing ("72 Westchester Dr", 22, 9, 000); Invest2.MonthlyExpense = 900; Invest2.IncomeFromRent = 1500.00; } Public Double GetExpenses () {Double Insurance; Double taxes; Double utilities; String in value; InValue = txtBoxInsurance.Text; //Console.ReadLine (); (Get user input from textbox) insurance = double. Purse (inverted); InValue = txtBoxTax.Text; //Console.ReadLine (); (Get user input from textbox) = double. Purse (inverted); InValue = txtBoxUtilities.Text; //Console.ReadLine (); (Get user input from textbox) utilities = double. Purse (inverted); Return (insurance / 12 + tax / 12+ utilities); }}} As I have seen before you C # people, I have met an error 'an object reference non-static field, method, or
Edit I have static zero main () in the second class if it changes anything.
mat
I think you are getting the error on inValue = txtBoxInsurance.Text The reason for this is that your GetExpenses () method in the static class is. When txtboxInsurance is the private and non-static property of the class Form1 . You can not access static methods from non-static method properties. What you can do instead
Public Static Class YourStaticClass Static String _ Insurance; Static String _tx; Stable string _ qualification; Public stable double GetExpenses () {double insurance; Double taxes; Double utilities; String in value; // console Write (Annual Insurance: "); InValue = _insurance; //Console.ReadLine (); (Get User Input From Textbox) Insurance = Double Purs (InValue); // Console. (Yearly Tax:"); InValue = _tax; //Console.ReadLine (); (Get user input from textbox) = double. Purse (inverted); // console Write (Monthly Utilities: "); InValue = _utilities; //Console.ReadLine (); (Get User Input From Textbox) Utilities = Double Purs (InValue); Return (Insurance / 12 + Taxes / 12+ Utilities); } and
public partial section Form 1: Form YourStaticClass._insurance = txtBoxInsurance.Text; YourStaticClass._tax = txtBoxTax.Text; YourStaticClass._utilities = txtBoxUtilities.Text; I think this should work
Comments
Post a Comment