β Help with coding
I'm trying to create an application where it can calculate the revenue. I am very new to coding and I'm not sure where to even start . Help is very much appreciated
82 Replies
I'd start with some $helloworld tutorials
Written interactive course https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/tutorials/
Videos https://dotnet.microsoft.com/learn/videos
In this particular case, if the screenshot is to be believed, you'd start with a new project using Windows Forms
$newproject
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework.
.NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended.
https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
And you'd use simple math, adding and multiplying, to calculate the total
its an assignment that i Have to do and I have done 2 other projects.
I can design the layout and everything but the issue is with the coding.
I just can't figure out how to multiply an assigned value by userinput
I haven't worked with Winforms, truth be told, but shouldn't getting a value from an input be as simple as
theInput.Value
?we have to use Windows Forms App(.NET Framework).
I'm new to all of this so it's hard for me
Ah, well, it's a school project so I guess using outdated technology is expected
Generally, though, Microsoft's docs will be of help
As will be some googling
winforms get value from user input
, winforms set label value
and so onRemember, textboxes values are strings. To do math on them, you need them to be a numerical type.
Can you name an appropriate numerical type?
like int right
yea i did some researching and i managed to get this
I'm on the right track i believe
Looks about right
okay I will try to finish the remaining colunms and ill come back
I think it looks good jsut needs to be touched up
Hey, congrats! It seems you basically got it done!
Almost. There are also some other criteria like when I leave a blank value, an error will come up
also have to make a Resset button, but don't know how to clear the right side of it.
same way you clear the left π
but the right side are Labels not Textboxes
their values are still modifiable π
They still have a value you can set
I maybe be just overlooking it
If you can set the value to a number or a string... you can set it to an empty string as well
look at how you set the value when the user clicks the button
do that, but with... no value at all.
its 1:34AM i'm burnt
Mind giving me a hint T_T
""
nvm
LMAO
hungarian notation :x
lol
Next problem is being able to leave a text box blank without it having an error
hint:
Convert.ToDecimal
is bad. decimal.TryParse
is goodit still gives me a error code
let me guess, you just replaced convert with tryparse without reading up on what makes them different?
yes
i dont think we are using decimal.TryParse yet
I'd at least use
decimal.Parse()
thenIm giving you a chance to learn how to be a programmer here. Go read the documentation for
decimal.TryParse
The
Try
patter ins super useful and super powerful, but a plain .Parse()
is definitely easier to understand and useI want to finish this assignment then learn more about
But I appreciate yβallβs help I will continue it tomorrow
Do you need more help? If so, what?
My mortal enemy.
right now i need to work on an if statement I think? WHen i leave a textbox open and error will occur
and instead of the error I need to have like a message box pop up
There is an onleave function that you can use
you should just check for empty fields..if it is empty, don't try to process it
or better yet, if the input fails to parse to a number, you can show a message box
I wonder if there was a way to try and parse strings to numbers...
I will look into that after class
Looking Into, apparently we use basic try/catch structure
Instead of making a new post, so what i have here is another code that I already did but my professor mentioned like the unsed blocks of code i had.
I couldnβt find the remove unused references button
this is a winforms problem. when you doubleclick a control in the winforms designer, it automatically creates an event handler for the "default" event and connects them
if you find the controls listed above (label1, label3, textbox2 etc) in your designer, you can show their event mappings and remove them
that will remove the references, and you can then remove the code
Ohhh okay thank you
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.back to this project, I have to create a limit on the tickets
Seems straightforward enough
yes
however
So i got it to where it would say "you;ve reached limit" blah blah
Yup
but it still caculates the reveune after i click ok
I'm guessing you just do
if(...) { MessageBox.Show(); }
thats what i have
well, of course it then continues
you have not added instructions for it to not continue
if you want to stop the method execution, you must
return;
well why thank you
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.My professor said this about the project
so what I did was made it to the point where it accepts only number inputs
would this be acceptable?
This won't show the user any errors, though
And the first point is about displaying descriptive errors
and you've also not handled numbers below 0
the only error it will show is if i leave it blank
it won't allow negative numbers
or decimals
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.how would i Start coding this?
so far i've made it to where the highlighted textbox only accepts letters
Yeah, now take that value and see if it's
gold
or platinum
string.Equals()
will be of use
And StringComparison
enumdunno if it goes against the assignment, but a better choice for only accepting 3 values is a dropdown combo box
instead of a textbox
I assume strings
Yeah
Same, but good ux is good ux π
I can paste all the listed requirements if that helps?
We are still in the basics
Just use a textbox then π
In a real app, a combobox would be better thou
I just got back home but so it would be like String str1 = "Gold"; String str2 = "Platnium"; ?
Not sure how that would help you, no
You need to check if the entered value is gold, platinum, or empty/none.
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.