|
Again, both of your responses have absolutely nothing to do with the original problem and this one is just plain ridiculous.
Darren Shields wrote: get an error saying " input string was not in a correct format"
Nothing at all in your response even remotely tried to help with this.
ely_bob wrote: this would circumvent the need to use a text box anywhere in the application
And how do you get data from the user, telepathy?
Quit while you're behind and go back to the cave.
only two letters away from being an asset
|
|
|
|
|
Darren Shields wrote:
I am trying to write a program that will generate random scores for football games...
He never said that the scores were to be inputs.. so the problem he is having is that he is trying to see what the RNG is doing before he uses the number(probably saving the random into the text field then pulling it back out to calculate)
HE NEVER SAID THERE WAS USER INPUT!
|
|
|
|
|
ely_bob wrote: HE NEVER SAID THERE WAS USER INPUT!
You're correct. However, any reasonably intelligent person would be able assume from score.TEXT that it is coming from a textbox and not a custom class with a Text property.
ely_bob wrote: so the problem he is having
No, that was not the problem he was having. Read the post again. It was clear what the error was.
Again, quite while you're behind or take it elsewhere
And thanks for the maturity of the 1 votes
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: You're correct. However, any reasonably intelligent person would be able assume from score.TEXT that it is coming from a textbox and not a custom class with a Text property.
However any beginning programmer (which he mentioned) would make this mistake and fixing that mistake is actually more useful to us than telling us how to fix poorly thought out code. Anyone reading the question would have wondered why he decided to do a text string when the program was using rng to make the scores itself. I did, and I have been using C# for less than 4 months.
Mark Nischalke wrote: No, that was not the problem he was having. Read the post again. It was clear what the error was.
The problem he was really having was he was using text where an int was a much more elegant, effective and simple solution.
Mark Nischalke wrote: And thanks for the maturity of the 1 votes
That was me. Your behavior in regards to the other user has been less than impressive. Your first one simply mocked him and didn't pay attention to what he said. Which was "If using RNG, DON'T USE TEXT!" and that, sir is 100% correct. He responds pointing out text is not needed and that his code block (a good one I might add) would help tighten up the code. Again, a good answer.
You respond by calling his responses ridiculous and then asking if telepathy is used in getting the answer when the obvious answer was supplied by the original question. RNG DONE BY THE PROGRAM.
You did a good job answering the original question. I concede that.
But the original question was framed from the wrong mindset and in fixing that code but not the underlying problem with the logic of the code, you don't actually help the user. Had I asked a similar question a few months ago and gotten the answer you gave, I would very good at converting text to int, but my code would be horrible because I was doing it all the time instead of using a much more effective system like maybe just using int values passed on from a random number generating function.
The reply given was not useless and irrelevent. IT FIXED THE LOGIC BEHIND THE ERROR. Good code would never have attempted to make a random number, pass it to a text box as a string, and then use the string as an int in a score tabulation.
|
|
|
|
|
Mark Nischalke wrote: And thanks for the maturity of the 1 votes
It appears these threads are becoming more common... I tried to balance out the negativity, but silver membership can only do so much...
|
|
|
|
|
The original statement said the program was making random scores for the games.
How would YOU propose the user get the random number from the program in order to input it in a text box that would then be converted to an int to be used by the program?
I don't understand why he would have made it a text string in the first place either. The best answer to the question is to fix the logic behind the decisions. I'm a novice programmer and I would have doen the same thing at first. I read some articles here and some books and I am figuring out that the most elegant code is the one that uses the least amount of convoluted conversions.
Would you make an int value convert to string, export it to XML, read it in a different spot in the program and then convert it to an int to be used in a math equation? Or would you just have the original number be used in the math problem directly?
Step 1: Make a random number generator.
private int RandomScore()
{
Random randomNumbers = new Random();
int randomScore1, randomScore2;
for (int nmbr = 1; nmbr<55; nmbr++)
{
randomScore1 = randomNumbers.Next(1, 100);
randomScore2 = randomNumbers.Next(1, 100);
}
}
(and yes, I am aware it may not be a valid score for American football. Changing values in there will get the results you want.)
Use this to get the input and you completely remove the need for string conversions.
After this you use code ely_bob used and you essentially have everything you need. No need to have the user generate a random score.
|
|
|
|
|
As you and ely_bob can see from the OP, the problem wasn't in generating a random number.
Darren Shields wrote: get an error saying " input string was not in a correct format"
The reply given did not address this and is useless and irrelevant.
only two letters away from being an asset
|
|
|
|
|
Mark You are correct As stated it doesn't solve the "Asked question"
But that is the problem ... His question stated a deeper issue..
You are Duck taping his Coding rather then helping the code become better.
Just because he can't get a Int>String conversion doesn't mean that you should fix the Int>String part of his program... this doesn't help him learn.
You should ask him why in a self stated black box approach he is using a int>string>Int conversion... this is a bigger issue then 0 O differences.. which admittedly I didn't see(I'm dislexic).
As most beginners do (and I still do .. Often) I like to see what my code is doing.. I can easily see how, without having been exposed to it yet, someone might think this is acceptable or even a good coding practice...
And as someone who is probably wrong more then I am right I will easily say I was wrong. However we should all do the Right thing in answering a random question such as this..
And that is Help the person grow, not patch up code that is looking at the issue .. Askew.
|
|
|
|
|
Thank you.
and I didn't vote him down... I only do that to absolute crap.. and what he said from his perspective is Correct.
I just suck at explaining things.
|
|
|
|
|
I know you didn't. I did. (and once I admitted it I suddenly got a single 1 vote in every comment I've made...)
Saying your response was useless when it addressed an underlying problem in logic was uncalled for. Calling your responses ridiculous was also uncalled for.
I didn't downvote his origianl answer as that was a good answer to the question as posed.
Your answer would have helped me with my code and in fact is much tighter than similar code I have been doing just to grasp the language. I've already copied into a program for study and use.
If the OP gets what you answered with he'll do much better.
modified on Friday, October 23, 2009 2:54 PM
|
|
|
|
|
ragnaroknrol wrote: I know you didn't. I did. (and once I admitted it I suddenly got a single 1 vote in every comment I've made...)
Well ain't that the pot calling the Kettle Black.
|
|
|
|
|
Maybe. But none of them were downvoted until I did.
And like I said, his original answer was good. I just downvoted everything with namecalling.
|
|
|
|
|
The problem is most likely that a value has been entered into the textboxes that can't be converted in an Int16.
Usually this comes from not entering a value in the textbox. You can prevent that for generating an exception by doing this.
Convert.ToInt16(score.Text.Length == 0 ? 0 : score.Text)
If the textbox is required to be filled in then you need to validate it before using it. Also, you can prevent exception from invalid values like this
int scoreOut = 0;
if( int.TryParse(score.Text, out scoreOut) )
{
... valid value
}
only two letters away from being an asset
|
|
|
|
|
I remove this topic to WCF forum.
Sorry....
modified on Friday, October 23, 2009 12:08 PM
|
|
|
|
|
|
1. There is WCF forum.
2. Post the error message as well.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
|
Really I don't understand you. You say "You should also have asked this in the WCF forum as it is specific to that topic, not c# in general ".
Are you kidding?
Sorry again...
|
|
|
|
|
What don't you understand? The question was WCF related not a general C# question and as such should have been placed there. However, since you had received answers here it should have been left here.
Read the forum guidelines
6. Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
only two letters away from being an asset
|
|
|
|
|
I agree with the OP here. This is a WCF related post hence belongs to that forum. When the user does that, you cannot blame for reposting.
Mark Nischalke wrote: Delete the other before someone answers there
Is this in the poster's control?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
d@nish wrote: Is this in the poster's control?
Yes.
d@nish wrote: When the user does that, you cannot blame for reposting.
The damage was already done. As the forum guideline state
6. Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
only two letters away from being an asset
|
|
|
|
|
I'm new to C# coming from C/C++, hence the question. I'm receiving data from a tcp connection into a byte array. Then I want to send a portion of the contents on to another tcp connection. How do I do that? For example, I get 50 bytes but want to send out only from byte 25 to byte 50. How would I access and copy this "subarray" into another array?
Thanks
|
|
|
|
|
Array.Copy lets you copy arrays (full or segments) from one to another.
|
|
|
|
|
|
Dear Sirs,
I'm using a textbox control to display some text and the text on the right is appearing scrunched. It looks as though it displays the first x distance (I'm pretty sure it looks to be measured in distance, not characters) normally, and then squishes the characters (horizontally) taking out all character spacing so that they're not overlapping, but touching. Perhaps I'll give you a picture...I can't see how to insert one into the post, so I'll give you a link to my SkiDrive. My sky-drive photo. As you can see from the photo, the text is scrunched on one row, but not two rows down!! If you can tell me how to fix this, let me know. THANKS!!
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|