Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating fields from form
    primarykey
    data
    text
    <p>I'm having a small problem with this program. This program is designed to use polymorphism. I have written one base class and two derived classes.</p> <p>We are supposed to make a base class(bank Account) array and fill that with three bank account objects. We then assign each bank account object a new object using it's overloaded constructor.</p> <pre><code> public partial class Form1 : Form { //Base class array BankAcct[] b = new BankAcct[3]; public Form1() { InitializeComponent(); //This is not getting current values from form! int accountNum; int atmNum; int pinNum; an = Convert.ToInt32(accountNumber.Text); p = Convert.ToInt32(pin.Text); atm = an - p; //base class b[0] = new BankAcct(name.Text, 500.00M, accountNum); //this derived class inherits from bankAcct name, account number, and //the decimal which is the balance assigned to the Account //private variables are atm and pin in this class b[1]= new SilverBankAcct(name.Text, an, 1500.00M, atmNumber, pinNum); //this derived class inherits from SilverBankAcct atm, pin, //has one private variable the decimal at the end which is the interest b[2] = new GoldBankAcct(name.Text, accountNum, 25000.00M, atm, pinNum, 0.05M); } </code></pre> <p>My problem is that when I instantiate my objects in the Form1 Constructor The fields do not update from the form and the current values in those fields are being ignored. I tried assigning the information by accessing properties in my base class and assigning the values from the form there, but the problem comes when I try to update my atm number and pin number which are private variables that go into my SilverBankAcct class, and GoldBankAcct class.</p> <pre><code>private void button1_Click(object sender, EventArgs e) { b[0].fName = name.Text; b[1].fName = name.Text; b[2].fName = name.Text; //do the same for account number which works, but how am I supposed to update atm and pin from the form when I have no access to these variables I only have access to the base class? } </code></pre> <p>What would be a better way to ensure that the values being passed along are being updated to the current values from the form when the button is clicked?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload