![]() |
|
[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
|
Simple Counting - unknown321 - Aug 20, 2019 Looking for help with simple counting. Heres the program im working on the very first part of the add button but getting error on line 2. Making the score total textbox add score textbox System.FormatException: 'Input string was not in a correct format.' ![]() Code private void BtnAdd_Click(object sender, EventArgs e)RE: Simple Counting - CynicalCheshire - Aug 20, 2019 I can try to help you debug more but I would need to see the rest of the .cs class and the .xaml class for the project. Specifically how the txtScore look and the txtScoreTotal look like. Are you making sure they're binding correctly. The second line of code compiles fine as the following. Code decimal score = Convert.ToDecimal("98");RE: Simple Counting - unknown321 - Aug 21, 2019 (Aug 20, 2019 08:37 PM)CynicalCheshire Wrote: I can try to help you debug more but I would need to see the rest of the .cs class and the .xaml class for the project. Specifically how the txtScore look and the txtScoreTotal look like. Are you making sure they're binding correctly. The second line of code compiles fine as the following. Code using System;that's all I have right now. I need it to point to the textboxes so I can use the textboxes. Its just not working right though. I keep getting that error. RE: Simple Counting - Blanka - Aug 21, 2019 wdyw to convert to decimal ? RE: Simple Counting - unknown321 - Aug 21, 2019 (Aug 21, 2019 07:54 AM)Blanka Wrote: wdyw to convert to decimal ? the text inside the textboxes. Is there a better way of doing it? RE: Simple Counting - Blanka - Aug 21, 2019 (Aug 21, 2019 08:22 AM)unknown321 Wrote: the text inside the textboxesyes but you can convert it to Int32 why decimal ? ( decimal are 12.34 or 456,789 ) RE: Simple Counting - unknown321 - Aug 21, 2019 (Aug 21, 2019 08:23 AM)Blanka Wrote: yes but you can convert it to Int32 why decimal ? ( decimal are 12.34 or 456,789 ) I tried int32 right now and still getting System.FormatException: 'Input string was not in a correct format.' im just entering random numbers but its not working RE: Simple Counting - BeatMatch - Aug 21, 2019 (Aug 21, 2019 08:28 AM)unknown321 Wrote: I tried int32 right now and still getting System.FormatException: 'Input string was not in a correct format.' int x = Int32.Parse(txtScore.Text); this should help this will take the text value, and store it as an int which you need as x, then so on. RE: Simple Counting - unknown321 - Aug 21, 2019 (Aug 21, 2019 09:18 AM)BeatMatch Wrote: int x = Int32.Parse(txtScore.Text); even so while trying this method still getting System.FormatException: 'Input string was not in a correct format.' on line int TotalScore = Int32.Parse(txtScoreTotal.Text); RE: Simple Counting - BeatMatch - Aug 21, 2019 (Aug 21, 2019 01:03 PM)unknown321 Wrote: even so while trying this method still getting you are trying to capture total score as an int then parse it into an int, capture it as a string, or you could use a bool aswell would work if you know how to use that. you would also neeed to parse all of the above in the code or its going to through out an error. Code void RunMainMenu(string input)i decleared int level at the top of my file your's will be slightly diffrent because you are using .text but thats the best example i have on hand. RE: Simple Counting - INeedHelpWithMyAccount1 - Aug 22, 2019 To be honest I didn't understand what you wanted to code. I mean the functionality. RE: Simple Counting - MavenGradle - Aug 22, 2019 (Aug 21, 2019 01:06 PM)BeatMatch Wrote: you are trying to capture total score as an int then parse it into an int, capture it as a string, or you could use a bool aswell would work if you know how to use that. What is this? Are you gonna write an if statement from 0 to 9 to check if the text is a valid number? Code int.TryParseRE: Simple Counting - BeatMatch - Aug 22, 2019 (Aug 22, 2019 07:57 AM)MavenGradle Wrote: What is this? Are you gonna write an if statement from 0 to 9 to check if the text is a valid number? 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, i already told him to try to int pars, but dont you worry about my code bud it runs smooth and does a job what i want it to do obviously there is more missing and thats just a snippet RE: Simple Counting - vaiperboy - Aug 22, 2019 (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 clearly seem to be lost, look up some basics buddy @OP, if you can, always use int.tryParse, it handles the conversion process (or failure, if there is. No exceptions will be raised, just a simple boolean value) RE: Simple Counting - BeatMatch - Aug 22, 2019 (Aug 22, 2019 11:00 AM)vaiperboy Wrote: You clearly seem to be lost, look up some basics buddy I seem to be lost considering, my code works umm no sir you are mistaken |