lundi 30 janvier 2017

C# Changing Float Values with "Combo Box Selected Change"

I am trying to change Float values via a combo box with an if statement.

Id doesn't have to be an if statement but I figured it would of been the most logical way to approach this.

However when I try to change a float with an if statement from selected change on a combo box I get massive errors...

I want it to reflect a formula later on in the program, outside of the scope, so the floats change based on what they have selected in the dropdown.

My "IF" Statement

public void cmbSubClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbSubClass.SelectedIndex == 1)
            {

               public float a = 0.86F; 
               public float b = 0.61F;
               public float c = 1.86F;  
            }
            if (cmbSubClass.SelectedIndex == 2)
            {
               public float a = 0.64F;
               public float b = 0.75F;
               public float c = 1.42F; 
            }
        }

An example of the Formula:

float zFormula = (a * val1) + (b * val2) + (c * val3)
textbox1.Text = Convert.ToString(zFormula);

I've tried to replicate the same thing with a class, but I can't seem to figure out how to do so.

Aucun commentaire:

Enregistrer un commentaire