I have tried going through similar questions and answers about this topic but I can't seem to find (or understand) a solution.
On Form 1 I have three text boxes that will receive user input. In a separate class I have a method that needs to access the input from those text boxes.
Form1.cs consists of just the text boxes and some buttons. The method in the other class is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RealEstateApp
{
public class RealEstateApp : Form1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
const double RENTAL_AMOUNT = 1000.00;
RealEstateInvestment invest1 = new
RealEstateInvestment(2004, 150000, "65th Street");
invest1.MonthlyExpense = GetExpenses();
invest1.IncomeFromRent = RENTAL_AMOUNT;
invest1.DetermineMonthlyEarnings());
RealEstateInvestment invest2 = new
RealEstateInvestment("72 Westchester Dr.", 229000);
invest2.MonthlyExpense = 900;
invest2.IncomeFromRent = 1500.00;
}
public double GetExpenses()
{
double insurance;
double taxes;
double utilities;
string inValue;
inValue = txtBoxInsurance.Text; //Console.ReadLine(); (get user input from textbox)
insurance = double.Parse(inValue);
inValue = txtBoxTax.Text; //Console.ReadLine(); (get user input from textbox)
taxes = double.Parse(inValue);
inValue = txtBoxUtilities.Text; //Console.ReadLine(); (get user input from textbox)
utilities = double.Parse(inValue);
return (insurance / 12 + taxes / 12 + utilities);
}
}
}
As I am sure you experienced c# guys out there have already noticed, I am met with an error 'An object reference is required for the non-static field, method, or property.'
my static void Main() is in the second class if that changes anything.
EDIT
I have put the whole class code above now to give a better idea of what's going on.
Cheers,
Matt