|
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
|
|
|
|
|
one of three three things:
If you are "creating your own" text box.. I really recomend against it.. use the Rich text or normal text box... but if you are you are using GDI+ to do the drawing in which case you should be using Graphics.DrawString()... not cycling threw your characters.. this looks like what the problem is.. remember that if your want to use this approach that you will need to add in the letter padding manually (X+=3; ).
Now if that is not the case:
You may have inadvertently set a flag somewhere for your first string and then re initialized(clearing the flag) for the subsequent strings.
Lastly if you are using different fonts, or units of measure you may get a squinched string...
But you could post some code.. that might help.
|
|
|
|
|
Dear Mr. ely_bob,
Thanks for your response! You know what...now that you mention it, It might be using GDI+ that the text is being drawn. I just realized that the TextBox control is used for EDITING the value, not displaying it! I keep forgetting that it's programmed that way. I'll look at it. So you think that maybe what's happenning is that the x += 2; is not persisting; okay, I'll check it out. Thanks again.
[====EDIT====]
It looks like this is the code used to draw the strings:
context.Graphics.DrawString(label, _font, _brush, clipRect, _format);
Yup...just checked, and I see where it drew my string. So...let's see.
the arguments
label = "0.0\0.0\-25.0\0.0\0.0\-25.0\0.0\0.0\-25.0\0.0\0.0\-25.0\0.0\0.0\-25.0 "
_font = {[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3, GdiCharSet=0, GdiVerticalFont=False]}
_brush = {System.Drawing.SolidBrush}
clipRect = {X=418,Y=768,Width=338,Height=16}
_format = {[StringFormat, FormatFlags=FitBlackBox, NoWrap, NoClip]}
Now, I'm reading about the format.FitBlackBox property, it says
"...By default, characters are repositioned to avoid any overhang." I would guess that this is the effect I'm complaining about, but after changing that, I still have the effect. Let me know what you think.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
Dear All,
I have not used the datagridview in Windows applications, I am used to change the data before binding the data in ASP.Net. Is there such event in Windows side of Visual Studio 2008.
Thanks in advance for promt answer.
|
|
|
|
|
I am not sure that I totally understand your question but that doesn't normally stop me from trying to help.
Different Methods of Data Binding to a DataGridView[^] from here on Code Project might help you to get an understanding of the process.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
thank you.
|
|
|
|