❔ Form Problem
This is likely a very beginner mistake, but I have no idea how to resolve it. If I need to provide the additional details concerning what I’m trying to do in this assignment, I can provide that as well. But essentially, my problem is that I either get one of two error messages. First of all, I’ll get the error message that “X name does not exist in the current context” (a CS1061 error). But when I change every line with this error to accurately match the names of the labels in my Form Design, I am met with another error, this time under the “.Text” part of the very same lines that had the previous error. So it seems that there’s something wrong with using .Text in the 7 lines wherein .Text is underlined. What should I do?
16 Replies
how have you named your textboxes?
My textboxes in the Form Designer are named as follows:
Labels for User Input:
“Labor Charged”, “Quarts Used”, “Cost Per Quart”, “Sales Tax Rate”
Button Name
“Calculate”
Label Names for Results
“Subtotal”, “SalesTax”, “Total Cost”
you have conflicting variable names
you have a field named Subtotal, as well as a label named Subtotal, which creates a field in the designer code. you're accessing the same class because of the
partial
keyword
the standard naming convention for private field names usually are camelCase and start with an underscorethose are labels, not textboxes
in
CalculateButton_Click
you should refer to the textbox .Text
to parseAhhh okay, all of this is very helpful then thank you. I will update the code and see if that works then.
This makes sense then I see, as this was something I was questioning to myself in my head. So for clarification, I should name the textboxes appropriately? Because right now, I just have them as “Textbox 1”, “Textbox 2”, etc. (the default), since I wasn’t sure if I am supposed to name them along with the labels.
Definitely, so that anyone who sees the name understands what it is for
Okay thanks a lot for that, this seems to be my main mistake. I’ll adjust to this then.
So you have a label + textbox for each data you want from the user?
If so, then as a naming example. Label = LaborCostLabel and the textbox = LaborCostTextBox
Yes that’s correct, a label + Textbox for LaborCharged, Quarts Used, CostPerQuart, and SalesTaxRate.
But ahhh okay, that makes a lot of sense
Perfect
As for the other three labels, I don’t have any textbox alongside it because Subtotal, SalesTax, and TotalCost are what I want the calculated results to be. But I was wondering to myself how the results will be displayed? Do I need to add text boxes to these as well?
It's up to you
If you're already using label + textbox combo, go with it all the way
Gotcha, so it’s optional then? I’m definitely going to go with it if so, just to be consistent with it. I just wasn’t sure how it would display the results alongside the three result labels unless I have a textbox next to them.
You're the designer here
Keeping it same across the UI is generally good
Understood 👍
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.