Havel The Gravel
Havel The Gravel

Reputation: 21

My method to clear the form isn't working for the global variables, but works fine on the local variables

 private void ClearForm(double total, double subtotal, double salesTax, double sPrice, double quantity, double orderTotal, double orderQuantity)
    {
        sPrice = 0;
        subtotal = 0;
        total = 0;
        quantity = 0;
        salesTax = 0;

        orderQuantity = 0;
        orderTotal = 0;

        lblStatus.Text = "";
        lblSalesTax.Text = "";
        lblSubTotal.Text = "";
        lblItemAmount.Text = "";
        lblTotal.Text = "";
        txtQuantity.Text = "";

        radClub.Checked = true;

        chkDiscount.Checked = false;
    }

This is my method to set my variables to 0, and clear the labels and text boxes. orderQuantity and orderTotal are global variables, and they are not getting cleared. The others are local variables, and are getting cleared. What my program does is calculate the price of an order for a sandwich shop, and I have a "New Order" button that is supposed to clear everything out so you can make a new order.

Upvotes: 0

Views: 29

Answers (1)

Eric J.
Eric J.

Reputation: 150108

orderQuantity and orderTotal are global variables

No, they are local because you have variables with the same name that hide the class level definition.

, double orderTotal, double orderQuantity)

To clear them in class scope,

this.orderTotal = 0;
this.orderQuantity = 0;

Or change the parameter names so as not to collide with class scoped variables.

Upvotes: 1

Related Questions