![]() |
|
[C#] Simple Counting - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Simple Counting (/showthread.php?tid=6000775) Pages: Pages
1
2
|
RE: Simple Counting - GraeskMytologi - Aug 22, 2019 (Aug 21, 2019 01:06 PM)BeatMatch Wrote: That's the most disgusting code I've ever read RE: Simple Counting - BeatMatch - Aug 22, 2019 (Aug 22, 2019 12:36 PM)GraeskMytologi Wrote: That's the most disgusting code I've ever read good for you if you can tell me, even what it does or what it calls, considering, there is more to that. RE: Simple Counting - vaiperboy - Aug 23, 2019 (Aug 22, 2019 11:23 AM)BeatMatch Wrote: I seem to be lost considering, my code works umm no sir you are mistakenlol get off the thread already please @OP, like i said simply use int.TryParse (or uint if you dont want to allow negatives or need a higher value [or even ulong if you need it]) usage: Code bool isNum = int.TryParse("123", out int value);
RE: Simple Counting - BeatMatch - Aug 23, 2019 (Aug 23, 2019 08:29 AM)vaiperboy Wrote: lol get off the thread already please use guys are just repeating what has been said lol read all the posts 🤣 RE: Simple Counting - GraeskMytologi - Aug 23, 2019 (Aug 22, 2019 12:59 PM)BeatMatch Wrote: good for you if you can tell me, even what it does or what it calls, considering, there is more to that. Well it clearly does up to 3 consecutive string comparisons, then parses the input string to an int and calls the AskForPassword() method. Not sure why that matters, that is still the most disgusting code I've ever read RE: Simple Counting - equity - Aug 23, 2019 (Aug 21, 2019 01:03 PM)unknown321 Wrote: even so while trying this method still getting Make sure you're entering numbers in the box (I know you probably are) you can try Convert.ToInt32(someTextBox.Text); RE: Simple Counting - CynicalCheshire - Aug 24, 2019 @OP I'm not sure if you have been able to get this to work but I think what may be going on is the text box has not been updated with the text input you put in your gui. That exception occurs when the input text is blank. Code decimal score = Convert.ToDecimal("");the above will cause your exception. My suggestion is two parts. 1. use the previously noted Code if(Double.TryParse(txtScoreTotal.Text, out double number)){and 2. check your bindings because it appears your Text has not updated properly to contain the input you desire. Good luck! Edit: to test if its your input just try to print it out and see its value or breakpoint it in debug mode. RE: Simple Counting - unknown321 - Aug 25, 2019 (Aug 24, 2019 02:05 PM)CynicalCheshire Wrote: @OP I'm not sure if you have been able to get this to work but I think what may be going on is the text box has not been updated with the text input you put in your gui. That exception occurs when the input text is blank. still getting same error with the code you told me to try RE: Simple Counting - 0xDEAD10CC - Aug 25, 2019 (Aug 24, 2019 02:05 PM)CynicalCheshire Wrote: @OP I'm not sure if you have been able to get this to work but I think what may be going on is the text box has not been updated with the text input you put in your gui. That exception occurs when the input text is blank. double and decimal are different types (Aug 22, 2019 08:29 AM)BeatMatch Wrote: no, why would i do that i was showing him an example of a bool, clearly he is new to coding, hence im not actually just using c# im also running it through a game engine and in only, wanted to use them 3 hence why i use input and not textbox.text because i have declared it somewhere else, :/ .. You wouldn't even need compiler optimization to improve code like that. An elementary student could probably optimize it by hand to produce more efficient code. Doing this for every string representation of a number is not only going to increase conditional checks, it won't validate against arithmetic overflow. Counting input, sum, and average is a very trivial task. What's wrong with a NumericUpDown control? Also, people who are suggesting to use the Convert class over the Parse()/TryParse() methods don't understand the difference in what these methods are doing behind the scenes. (Aug 25, 2019 11:58 AM)unknown321 Wrote: still getting same error with the code you told me to try If you're getting an error, you're doing something wrong at runtime with your input. What is an example input? "1234" should parse with Parse() and TryParse() with zero issues. My guess is that you're using the wrong textbox... txtScore.Text instead? TryParse() won't throw an exception either. One other issue here is that you're using the control's display text to continue with your calculations which is the opposite of how software is normally developed. UI is for display only, you bind data with your controls, or update it when your internal data changes. Parsing data that has been calculated and converted to a string to be displayed on the UI to be taken again, parsed back to the relevant type, and used in other expressions for calculations is wrong. |