C
C#11mo ago
cl_quandale

why does the label doesn’t exist in my code? im using .net c#

private void Button1_Click(object sender, EventArgs e) { int unitCost = 0; int quantity = 0; if (int.TryParse(TextBox2.Text, out unitCost) && int.TryParse(TextBox3.Text, out quantity)) { if (unitCost == 300) { Label10.Text = "$300"; } else if (unitCost == 500) { Label10.Text = "$500"; } else if (unitCost == 200) { Label10.Text = "$200"; } else if (unitCost == 100) { Label10.Text = "$100"; } int totalCost = unitCost * quantity; Label11.Text = totalCost.ToString(); } } private void Button2_Click(object sender, EventArgs e) { Label10.Text = ""; Label11.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; MessageBox.Show("Purchase successful!"); }
No description
10 Replies
SG97
SG9711mo ago
did you create those controls and is this WinForms?
TheRanger
TheRanger11mo ago
By default when a control is generated, it's name is in Camel case label10, textBox2, etc...
cl_quandale
cl_quandaleOP11mo ago
Yes
SG97
SG9711mo ago
for both? can you show the form's designer
Buddy
Buddy11mo ago
Not pascalcase but camelcase
cl_quandale
cl_quandaleOP11mo ago
I turned just turned off my pc 😭 Ill show you later but thanks tho
SG97
SG9711mo ago
aight
TheRanger
TheRanger11mo ago
eh, i typo'd sry lol I didn't realize i typed the wrong word lol
Mayor McCheese
Mayor McCheese11mo ago
I give 10:1 odds on they're not working with the form code behind.
PracticeMedicine
PracticeMedicine11mo ago
did you make sure that youve entered the correct control name?

Did you find this page helpful?