This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I've got maybe a simple question for you, but Im stuck with this one.
So, I have an application, which has multiple userControls, inherited from one class. I can drag them to a panel, and resize them. I have save and open features for userControl position/size saving/loading from XML file. Lately I improved it with a feature which lets you to add additional stuff to them in code, then save it with the rest of primary parameters.
Here's an example:
Basically it detects if any additional parameters have been added and save them under <Parameters> tag.
Here's an example of userControl code I added some stuff to:
Saving went well, but I'm stuck at loading part. I tried to test it at first by writing any discovered parameters to richTextBox, to see if it reads any data at all.
I thought, that it should work by detecting userControls first, then to look for parameters in each userControl.
I got this error:
As you can see below, the program reads the XML, but stops at the point, where richTextBox needs to be filled. It doesn't happen, because in the list, which should contain both parameters, there is just one parameter, kind of a hybrid.
I'm confused. Any advice?
Developer in training
Woaw, I'm so lazy :D
I forgot to convert parameters' inner texts :P
foreach (XmlNode pm in pmList)
{
int s = int.Parse(pm["RandomParameter1"].InnerText);
int ss = int.Parse(pm["RandomParameter2"].InnerText);
richTextBox1.AppendText(pm["RandomParameter1"].ToString() + " - " + s.ToString() + "\n");
richTextBox1.AppendText(pm["RandomParameter1"].ToString() + " - " + ss.ToString() + "\n");
}
Still need to work on parameter name output, as the result i get on textbox is:
System.Xml.XmlElement - 27
System.Xml.XmlElement - 10
System.Xml.XmlElement - 27
System.Xml.XmlElement - 10
System.Xml.XmlElement - 27
System.Xml.XmlElement - 10
Buuut, it's a start, isn't it? :D
Thanks for anyone who spared their time trying to fix my lazy mistake :)
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
Edit: Problem solved, the greater than was the wrong ascii character. Even tho I didn't copy paste it from somewhere. I'll have to check my keyboard language.
Edit: Just to make it clear, effect.Parry is an int? not a decimal. See edit below
Edit: I changed the decimalToString. That was an error on my part but I'm still getting the error
I am trying to do a greater than if statement in my code but I am getting an error and I just can't figure what the error is...
Here is the part of the code.
if (effect.Parry != null)
{
txtEffect += " Parry the next " + effect.Parry.ToString() + " attack";
if (effect.Parry > 1)
txtEffect += "s";
if (effect.NumberOfTurn != 0)
{
txtEffect += " over " + effect.NumberOfTurn.ToString();
}
}
And here is the error I get:
Erreur 1 Caractère '-' inattendu
In english it would be: Unexpected character '-'
Can someone explain me what I did wrong? I tried >= and it gives me the same error. If I try without > I don't get an error.
Edit: txtEffect is a string, effect.Parry is an int? (To allow nulls) I tried parsing it into a normal int and I get the same error as above.
Your problem came from defining effect.Parry as an int? and then passing it into a function requiring a decimal? as a parameter. Change one or the other so they match, and you should take care of your problem.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
not much to explain as I have no logical explaination as to why this is not working :s
Just to confirm, It is a 'jpeg' file extention, the name is correct and I don't see any other issue with why it would not work be found.
You're saving it to a filename ending with "jpg" and then loading from a filename ending with "jpeg". Assuming you're trying to load the file you've just saved, that's the problem.
(I'd copy the code to point out the lines in question, but you only included it as an image...)
I'd strongly suggest constructing the filename once, and using that variable twice:
// I prefer using Path.Combine over string concatenation, but both will work.
// You might want to change "Identitys" to "Identities" though :)
string file = Path.Combine(#"C:\", "SimpleSkype", "Identitys", dd + ".jpg");
SaveSkypeAvatarToDisk(u.Handle, file);
using (Image image = Image.FromFile(file))
{
...
}
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am currently working on a console text analysis program for an assignment.
My problem is, I need to save all user entered words above 7 letters to a text file. The user can enter words by typing in their paragraph or by loading from a text file.
Any ideas on how I can do this ?
Thanks for any help in advance
Without giving you the code, think about what you really need to do.
Read in the entire text.
Split the text based on spaces / punctuation to identify each word. This will be stored in an array.
Test each split string's length.
Write the results to a file.
I'm not sure how you're getting the user-entered words, but you can do a simple LINQ statement to get the words greater than 7 letters:
//get all words into an array (wordArray)
var bigWords = wordArray.Where(w => w.Length > 7).ToArray();
Then you do something with the bigWords array.
I'm not going to do your assignment for you.
You should check functions such as String.Split, String.Length and String.Substring()
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Im struggling to get the right syntax to use in c# for the vb function FormatNumber...i will say that 'iPremium' is an object as it returns data from a tableadapter.
the value that 'ipremium' holds is 943.4000 and the idea is to only have two decimal places after the '.', i would hope this is acheivable using the right syntax but unfortunately not being a c# expert, it could take a while to figure this out.
here's the vb code:
iPremium = FormatNumber(iPremium, 2, TriState.True)
any idea's on how this is acheivable?
thanks for any idea's and suggestions and excuse the ignorance if this is not worded correctly
var formattedNumber = iPremium.ToString("0.00");
or, if you wish to round the number, instead of just chopping-off precision:
var formattedNumber = Math.Round(iPremium, 2).ToString("0.00").Dump();
Here's a list of the various formats you can use with ToString: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
var roundedNumber = Math.Round(iPremium, 2);
var formattedNumber = String.Format("{0:#.##}", roundedNumber);
I assume the TableAdapter returns a Datatable which can also be used strongly typed:
// first row as example (add using.System.Linq)
double value = table.AsEnumerable().First().Field<double>("iPremium");
Now you can use String.Format or just ToString with a custom format:
string result = value.ToString("0.00");
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I'm porting a c++ class to C# and i have a difficulty.
I would like to find an equivalent of SpanIncluding.
Here is my cpp code :
while (Notes.Mid(j,1).SpanIncluding("0123456789").IsEmpty()!=NULL){}
Anyone can help me please ?
I believe SpanIncluding starts matching from the start of the string, stopping when the first non-matching character is found.
So one formulation in the general case would be this:
string match = new string(someString.ToCharArray().
TakeWhile(c => "0123456789".Contains(c)).ToArray());
(or an equivalent using a regular expression).
However, in the example given in the question there's only one character so the whole thing probably boils down to a test of whether this character is >= '0' and <= '9':
while(char.IsDigit(Notes[j])) { ... };
I found the MSDN page for SpanIncluding, and it seems like a ridiculously specific function. I can't really understand what it tries to solve, since it has some strange caveats.
LINQ would be one way of implementing it:
string text = "2334562";
IEnumerable<char> spannedChars = text.TakeWhile(c => "1234567890".Contains(c));
This is a more direct port of SpanIncluding than queen3's option, if I understand the MSDN page correctly, because the result set should stop the minute it hits a character not in the spanning string.