I have a dictionary that I am using to define the ratings of copper cable. I want to use these values to calculate how many cables it will take to meet a certain connections rating. The size of the connection, the cable type, and system type are selected by two ComboBoxs named cb_amperage, cb_cable_size and, cb_system_type. The answer found once the equation runs is to be displayed in a text box named tb6_cable_qty. I welcome any and all comments and suggestions. Thank you in advance for the assistance.
The math is easy:
decimal x, y, z;
x = decimal.Parse(cb_amperage.);
y = decimal.Parse();//<---- this value must come from the dictionary below
a = decimal.Parse();//<---- this value must also come from a dictionary below
z = (x / y) * a
tb6_cable_qty.Text = Math.Round(z,2).ToString();
void Cb_amperageSelectedIndexChanged(object sender, EventArgs e)
{
if (!String.!IsNullOrEmpty(cb_amperage) & !String.IsNullOrEmpty(cb_cable_size))
//not sure if the above is right but I think it coveys the idea
{
//function based on the values in the dictionary below
}
//Cable Dictionary 1 used for cable quantity calculation
Dictionary<string, int> cable_dictionary_1 = new Dictionary<string, int>();
cable_dictionary_1.Add ("#1", 130);
cable_dictionary_1.Add ("1/0", 150);
cable_dictionary_1.Add ("2/0", 175);
cable_dictionary_1.Add ("3/0", 200);
cable_dictionary_1.Add ("4/0", 230);
cable_dictionary_1.Add ("250", 255);
cable_dictionary_1.Add ("300", 285);
cable_dictionary_1.Add ("400", 355);
cable_dictionary_1.Add ("500", 380);
cable_dictionary_1.Add ("600", 720);
cable_dictionary_1.Add ("750", 475);
//System Type Dictionary used for cable quantity calculation
Dictionary<string, int> system_type_dictionary = new Dictionary<string, int>();
system_type_dictionary.Add ("3P 3W", 3);
system_type_dictionary.Add ("3P 4W", 4);
EDIT 1: mmr; please take a look at the code below. I have a feeling I missed something that I would know if I was a little more expierenced. The following is my implementation of the first part of the solution you suggested. I get an error. I think it is because these two items, the string and the dictionary dont know they are supposed to be linked. Here is the error; *Invalid token ',' in class, struct, or interface member declaration (CS1519). See what you can see. Thanks again.
//The following strings are used in the cable quantity calculation
private const string cblsize1 = "#1";
private const string cblsize2 = "1/0";
private const string cblsize3 = "2/0";
private const string cblsize4 = "3/0";
//Cable Dictionary 1 used for cable quantity calculation
Dictionary<string, int> cable_dictionary_1 = new Dictionary<string, int>();
cable_dictionary.Add(cblsize1, 130);//#1 Cable
cable_dictionary.Add(cblsize2, 150);//1/0 Cable
cable_dictionary.Add(cblsize3, 175);//2/0 Cable
cable_dictionary.Add(cblsize4, 200);//3/0 Cable