|
I usually store things on a per-user basis, but I think Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) is supposed to give you exactly that, regardless of which OS you're on.
|
|
|
|
|
Thanks for your help... and making me feel very ignorant.
I was looking at the list that had all of the special folders and saw CommonProgramFiles, COmmonDocuments, CommonPrograms, etc. After seeing your response, I looked at the list again and I bet you'll never guess what the second one was.
I was looking for something referencing public.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
Heh, don't feel bad... There's a ridiculous amount of content in the framework... I've done the same thing in other parts.
|
|
|
|
|
Hi there,
I know how to control the master volume of a system, but how I should do it individually for each speaker? - I didn't found any hint so far.
E.G.: A 5.1 or 7.1 System has 6/8 speakers and I want to reduce the volume of center and sub but increase the back speakers for example.
I'm creating an media player where I want to control the individual volume of those speakers.
I appreciate your help!
Zsolt / Germany
|
|
|
|
|
I want to automated call function "save as" and choise "save as type = webpage completed..." from Webbrowser Control (Windows Forms, C#).
I found the source code in link "http://www.codeproject.com/KB/shell/iesaveas.aspx?msg=1101501" but i can't understand C++. From this code i want to build a funtion DownloadHTMLCompleted(String URI, String FileName) by C++ or C#, then call this funtion from C#.
Help me!
|
|
|
|
|
Nguyễn Đức Thiện wrote: but i can't understand C++.
Nguyễn Đức Thiện wrote: build a funtion ... by C++
You say you don't understand C++ but want to create a function in C++
only two letters away from being an asset
|
|
|
|
|
yes!
I can't understand C++ but i can call this from C# (because i think may be anyone help me by C++, this way is faster)
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:31am.
|
|
|
|
|
Hi!
If I use File.WriteAllText(file_name, text_html) I can't save completed webpage (include: image, css, js,..)
|
|
|
|
|
Hi everyone, as already stated I am completely new to c#, I am trying to write a program that will generate random scores for football games in a league where each team plays one another once, however after generating the score i wish to assess which team should be awarded 3 points for winning or if both should be awarded 1 point, so I can produce these in a league table. I have written this code but get an error saying " input string was not in a correct format", here is the part of my code causing the error:
if (Convert.ToInt16(score.Text) > Convert.ToInt16(score2.Text))
{
points12 += 3;
}
else if (Convert.ToInt16(score.Text) < Convert.ToInt16(score2.Text))
{
points4 += 3;
}
else
{
points4 += 1;
points12 += 1;
}
Any help would be greatly appreciated
Thanks in advance
|
|
|
|
|
It would only make sense for you to get that error on the first line of code that you have posted but it would still have been nice if you had indicated the line.
The error means that either score or score2 contains something that cannot be converted into an int16 . Have you maybe entered an 'o' (letter O) rather than a 0 (number zero) or 'L' instead of 1?
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.”
|
|
|
|
|
My apologies, the error does indeed occur on the first lie of code posted.
I've check through my code however and there doesn't seem to be an instance where I've used a letter 'o'instead of number zero or letter 'l' instead of number one.
Thankyou though
|
|
|
|
|
It wouldn't be in your code, it would be what is entered into the TextBoxes (score and score2 ) but never mind.
In order to tie down where the error is you could make your code a little more long winded, temporarily, something like this:
Int16 score = Convert.ToInt16(score.Text);
Int16 score2 = Convert.ToInt16(score2.Text);
if (score > score2)
{
points12 += 3;
}
else if (score < score2)
{
points4 += 3;
}
else
{
points4 += 1;
points12 += 1;
}
That way you will get an error on the line for the incorrect text and can narrow down your search for a solution.
BTW: Do you notice how my code sample is nicely formatted? it is because I have surrounded it with <pre>code goes here</pre> tags. That doesn't format it for you but will preserve any formatting you put in. You can do it automatically by highlighting your code and clicking on the 'code block' widget, just above the reply text box.
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.”
|
|
|
|
|
Well you shouldn't be saving the data in text for, you should be saving it internally as a int, use this format:
class Game
{
public int GameScore;
public int LeageScore;
public Game(int S, int LS)
{
GameScore = S;
LeagueScore = LS;
}
}
class Team{
public List<Game> Games = new List<Game>()
public string Name;
public Team(string _Name)
{
Name = _Name;
}
public int CumulativeLeagueScore
{
get
{
int ret = 0;
foreach(Game G in this.Games){ret+=G.LeagueScore;}
return ret;
}
}
public void AddGame(int score, int leagescore)
{
this.Games.Add(new Game(score, leagescore);
}
}
that way when you want to add in things like statistics, and multiple years of records it will be easier.
But your issue is coming from using text somewhere in between your RNG(Random number generator) (probably Math>Random()..?) and your test.. Unless you are using dice and then typing it into a form... in which case only convert to int once and then whenever you want to display the info use ToString().
|
|
|
|
|
This did nothing at all to answer the question.
only two letters away from being an asset
|
|
|
|
|
Sorry I am too accustomed to talking to myself...
If You are Actually generating the numbers randomly then you shouldn't need text boxes.
If you use the class structure from before then your code will condense greatly and become easier to debug.
this would circumvent the need to use a text box anywhere in the application(assuming that you are not using an outside source to "randomly" generate the data). and Once that has been accomplished the "bug" would not be there.. (because there wouldn't be any string to int conversions).
I guess I am so against the notion of string-> Int that I see it and it makes me revert to a cave man.
|
|
|
|
|
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.
|
|
|
|