C
C#β€’15mo ago
Davin

❔ 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
No description
82 Replies
Angius
Angiusβ€’15mo ago
I'd start with some $helloworld tutorials
Angius
Angiusβ€’15mo ago
In this particular case, if the screenshot is to be believed, you'd start with a new project using Windows Forms $newproject
MODiX
MODiXβ€’15mo ago
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
Angius
Angiusβ€’15mo ago
And you'd use simple math, adding and multiplying, to calculate the total
Davin
DavinOPβ€’15mo ago
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
Angius
Angiusβ€’15mo ago
I haven't worked with Winforms, truth be told, but shouldn't getting a value from an input be as simple as theInput.Value?
Davin
DavinOPβ€’15mo ago
we have to use Windows Forms App(.NET Framework). I'm new to all of this so it's hard for me
Angius
Angiusβ€’15mo ago
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 on
Pobiega
Pobiegaβ€’15mo ago
Remember, textboxes values are strings. To do math on them, you need them to be a numerical type. Can you name an appropriate numerical type?
Davin
DavinOPβ€’15mo ago
like int right
Davin
DavinOPβ€’15mo ago
yea i did some researching and i managed to get this
No description
Davin
DavinOPβ€’15mo ago
I'm on the right track i believe
Pobiega
Pobiegaβ€’15mo ago
Looks about right
Davin
DavinOPβ€’15mo ago
okay I will try to finish the remaining colunms and ill come back
Davin
DavinOPβ€’15mo ago
I think it looks good jsut needs to be touched up
No description
Angius
Angiusβ€’15mo ago
Hey, congrats! It seems you basically got it done!
Davin
DavinOPβ€’15mo ago
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.
Pobiega
Pobiegaβ€’15mo ago
same way you clear the left πŸ˜›
Davin
DavinOPβ€’15mo ago
but the right side are Labels not Textboxes
Pobiega
Pobiegaβ€’15mo ago
their values are still modifiable πŸ˜›
Angius
Angiusβ€’15mo ago
They still have a value you can set
Davin
DavinOPβ€’15mo ago
I maybe be just overlooking it
Angius
Angiusβ€’15mo ago
If you can set the value to a number or a string... you can set it to an empty string as well
Pobiega
Pobiegaβ€’15mo ago
look at how you set the value when the user clicks the button do that, but with... no value at all.
Davin
DavinOPβ€’15mo ago
its 1:34AM i'm burnt
Davin
DavinOPβ€’15mo ago
Mind giving me a hint T_T
No description
Pobiega
Pobiegaβ€’15mo ago
""
Davin
DavinOPβ€’15mo ago
nvm LMAO
Pobiega
Pobiegaβ€’15mo ago
hungarian notation :x
Davin
DavinOPβ€’15mo ago
lol Next problem is being able to leave a text box blank without it having an error
Pobiega
Pobiegaβ€’15mo ago
hint: Convert.ToDecimal is bad. decimal.TryParse is good
Davin
DavinOPβ€’15mo ago
it still gives me a error code
Pobiega
Pobiegaβ€’15mo ago
let me guess, you just replaced convert with tryparse without reading up on what makes them different?
Davin
DavinOPβ€’15mo ago
yes i dont think we are using decimal.TryParse yet
Angius
Angiusβ€’15mo ago
I'd at least use decimal.Parse() then
Pobiega
Pobiegaβ€’15mo ago
Im giving you a chance to learn how to be a programmer here. Go read the documentation for decimal.TryParse
Angius
Angiusβ€’15mo ago
The Try patter ins super useful and super powerful, but a plain .Parse() is definitely easier to understand and use
Davin
DavinOPβ€’15mo ago
I want to finish this assignment then learn more about But I appreciate y’all’s help I will continue it tomorrow
KidAlchemy
KidAlchemyβ€’15mo ago
Do you need more help? If so, what?
Azrael
Azraelβ€’15mo ago
My mortal enemy.
Davin
DavinOPβ€’15mo ago
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
KidAlchemy
KidAlchemyβ€’15mo ago
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
Pobiega
Pobiegaβ€’15mo ago
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...
Davin
DavinOPβ€’15mo ago
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.
Davin
DavinOPβ€’15mo ago
No description
Davin
DavinOPβ€’15mo ago
I couldn’t find the remove unused references button
Pobiega
Pobiegaβ€’15mo ago
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
Davin
DavinOPβ€’15mo ago
Ohhh okay thank you
Accord
Accordβ€’15mo ago
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.
Davin
DavinOPβ€’15mo ago
back to this project, I have to create a limit on the tickets
No description
Pobiega
Pobiegaβ€’15mo ago
Seems straightforward enough
Davin
DavinOPβ€’15mo ago
yes however
Davin
DavinOPβ€’15mo ago
No description
Davin
DavinOPβ€’15mo ago
So i got it to where it would say "you;ve reached limit" blah blah
Pobiega
Pobiegaβ€’15mo ago
Yup
Davin
DavinOPβ€’15mo ago
but it still caculates the reveune after i click ok
Pobiega
Pobiegaβ€’15mo ago
I'm guessing you just do if(...) { MessageBox.Show(); }
Davin
DavinOPβ€’15mo ago
thats what i have
Pobiega
Pobiegaβ€’15mo ago
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;
Davin
DavinOPβ€’15mo ago
well why thank you
Accord
Accordβ€’15mo ago
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.
Davin
DavinOPβ€’15mo ago
My professor said this about the project
Davin
DavinOPβ€’15mo ago
No description
Davin
DavinOPβ€’15mo ago
so what I did was made it to the point where it accepts only number inputs
No description
Davin
DavinOPβ€’15mo ago
would this be acceptable?
Angius
Angiusβ€’15mo ago
This won't show the user any errors, though And the first point is about displaying descriptive errors
Pobiega
Pobiegaβ€’15mo ago
and you've also not handled numbers below 0
Davin
DavinOPβ€’15mo ago
the only error it will show is if i leave it blank it won't allow negative numbers or decimals
Accord
Accordβ€’15mo ago
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.
Davin
DavinOPβ€’15mo ago
how would i Start coding this?
No description
Davin
DavinOPβ€’15mo ago
so far i've made it to where the highlighted textbox only accepts letters
No description
Angius
Angiusβ€’15mo ago
Yeah, now take that value and see if it's gold or platinum string.Equals() will be of use And StringComparison enum
Pobiega
Pobiegaβ€’15mo ago
dunno if it goes against the assignment, but a better choice for only accepting 3 values is a dropdown combo box instead of a textbox
Angius
Angiusβ€’15mo ago
No description
Angius
Angiusβ€’15mo ago
I assume strings
Pobiega
Pobiegaβ€’15mo ago
Yeah Same, but good ux is good ux πŸ™‚
Davin
DavinOPβ€’15mo ago
I can paste all the listed requirements if that helps? We are still in the basics
Pobiega
Pobiegaβ€’15mo ago
Just use a textbox then πŸ˜‰ In a real app, a combobox would be better thou
Davin
DavinOPβ€’15mo ago
I just got back home but so it would be like String str1 = "Gold"; String str2 = "Platnium"; ?
Pobiega
Pobiegaβ€’15mo ago
Not sure how that would help you, no You need to check if the entered value is gold, platinum, or empty/none.
Accord
Accordβ€’14mo ago
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.
Want results from more Discord servers?
Add your server