Workshop calculate not working
Here is my code both in form1 and designer. I know I messed up and had a dislexic moment and switched two words around but when i try to fix it, it gives me errors. But I also cant get the calculate button to work when running the program. I just cant seem to get these assignments with calculations to work.
https://paste.mod.gg/eykezrwgbwdh/0
BlazeBin - eykezrwgbwdh
A tool for sharing your source code with the world!



54 Replies
Can you be more specific about what doesnt work and how it doesnt?
ie, what is the expected result, and what are you seeing
I'm seeing some unusual variable names thou, that might cause some confusion..
these are just variables for storing floating point numbers, they are in no way connected to their respective labels
also, all those variables are declared in the class member scope, but are only ever used as local variables in the
calculateButton_Click
method
@NightswyngApologies had to step away
so, i deleted the errors, but when I had the label double lodgingTotalLabel it is showing as unused

when i tried to change it to the totalLodgingLabel it would give me an error
All those variables are declared in the wrong place, if you ask me.
Every single one.

And that switch is a mess too :p
set the value with a switch expression, then update the label afterwards
will cut that down a lot in size and complexity
I am not sure what you mean
before
after
which one is easier to read and maintain?
the second one is alot cleaner
can you explain that last line
$"${lodgingFee}";
sure, the first dollar sign is BEFORE the string quotation mark
that means that string is using string interpolation
$ - string interpolation - format string output - C# reference
String interpolation using the
$
token provides a more readable and convenient syntax to format string output than traditional string composite formatting.a fancy way of saying, I want to "inject" some variables into the string
think of
{lodgingFee}
as a placeholder that will be replaced with the value of lodingFee
so it becomes $150
for exampleif i throw it in to VS, I would have to rewrite everything because its giving me so many errors, so how do I clean this up to work?
also with the current code, when I run the program and select each item, hit calculate nothing works or shows up in the 4 boxes
Am I using the wrong thing(label)?
I can't tell, because you didn't show that part of the code
oh you did, you just didnt give it a filename. okay
I see
lemme look
I don't see any binding to the click event
oh wow I see that now, there is no event
ie, your button doesnt actually invoke the method
how did that happen?
ĀÆ\_(ć)_/ĀÆ
also, I think you have several calculation issues too
totalCost = lodgingFeeLabel * registrationFeeLabel;
doesn't seem right
lodingfee TIMES registrationfee?
also, you update theactual lodgingfee label twice
both in the switch, with hardcoded values, then later with the calculated one (* days)
but ppleeease rename your variables lol
daysLabel
is a baaad name. numberOfDays
is muuuch betterI was going off the directions and previous instruction
I will change it
oh, and also
look at this beauty
š¤¤
switch expressions :catlove:
so when I put that in, it was telling me there was an error with the underscore
what error?
CS 7.3 and using something higher than 8.0
oh, you made the project using .NET framework 4.x
not modern .NET 9
yea, that was what I was told to use
For shame.
still learning the difference
Your teachers are bad and should feel bad.
.NET framework "died" in 2016
I can see schools not updating directly and still teaching old stuff for a few years, but 9 whole years?
I think thats why i am struggling, alot of the resources are showing different versions
Most resources online will assume modern .NET versions these days
again, it has been 9 years.
I will schedule a zoom meeting with my professor to clarify since we are going of the book, I don't want to be outdated in my learning
I think the book is in fact using the old version thou, unless I am remembering wrong
But pointing out there was no events in the designer helped immensely and it works!
We talked about this on your last thread, I think
You are correct, we did discuss that last time
so just to recap, if I were to write this, it'd be something like...
ahh ok, so you put the messages at the top pretty much to establish and get out of the way.
I really like the cleaned up version
and what is the throw new mean?
its how we do errors in C#
so the
_ => throw new ArgumentOutOfRangeException()
line means
"if its ANY OTHER value than the ones specified above, create a new error object and throw it up the call stack"oh ok
can you be my professor? š
I will have to add that to my notes for the future
Would if it paid decently š
Its an online class so whats some extra income?
lol I am gonna save your code to use as reference to clean up, but I was able to get the existing on working so I will submit that and set up with my professor one the version
The trick to writing code like this is to break the problem down into smaller problems and handle them one at a time
I was going over everything and couldnt figure it out until you pointed out there were no bindings then it clicked
We can't do anything if the user didn't select values, so we check that first. Then we get the numbers for the workshop, then the location, and finally we do the math
I have to remember to break it down, just get frazzled and lose sight
You are far from alone in doing that. The code you pasted looks a lot like what most beginners code looks like
its honestly what they show in the book
Its more natural to think "if the user selected a valid value, calculate the registration fee..."


Rather than "if the user didn't select a valid value, stop them"
Well the book is using ancient versions of C# so it doesn't have switch expressions :p
lol can you do me a favor, and if you have a more updated modern suggestion on a book, I will gladly get it and read it to improve the outdated basics
Sorry, I don't. The book I used to learn was outdated 20 years ago š
Gonna sleep, nn
lol thats ok and totally fair, jsut thought i would ask.
Thank you again for your help! much appreciated! sleep well