|
Use the Math.Abs()[^] method to get the absolute value of the difference when converting to years and months.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
hi Richard..thxx for the suggestion..i did try Math.Abs stuff but still not getting the desired result...
The conversion into months in negative scenario is what I am not getting..
Further assistance would be highly appreciated..
Regards
Anurag
|
|
|
|
|
anurag3487 wrote: The conversion into months in negative scenario is what I am not getting. I'm not sure what you mean by this but using a TimeSpan object will get you the number of days difference, and using the Abs() method will get you the number as a positive integer. Converting that into months and years requires some logic which takes into account leap years and the number of days in each month, none of which is impossible, it just requires a little extra thought.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
The general way to get the difference between two DateTime values is just to subtract and get a TimeSpan. A TimeSpan only goes as high as Days, not months or years because doing so is rather difficult -- you must take the varying lengths of months and Leap Days and into account.
It were easy and reliable, it would be built-in. If you really want to do this, you're on your own. I seem to recall that someone else asked about this a few months back, but a quick search didn't turn it up.
|
|
|
|
|
PIEBALDconsult wrote: you must take the varying lengths of months and Leap Days and into account.
I'm not saying that it's right, or that anyone should do it, but what about the Datediff function in the Microsoft.VisualBasic namespace? There you'r able to get the difference in months and years without that hassle.
But saying that, I've not used that namespace in a C# solution.
|
|
|
|
|
See David Morton's answer on this[^] page.
/ravi
|
|
|
|
|
thanks a lot everybody for the responses..
will do evrything what is required to crack it...
|
|
|
|
|
I think code "ts.Days/365" is not right,leap year should be considered
|
|
|
|
|
hi all..have found the solution to the problem above posted by me..thxx evryone fr their suggestions..will post the answer sometime...
|
|
|
|
|
Hey Guys,
Quick question, I need to find TrackBar's Scroll Box/thumb/slider position in pixels. I need to put a ToolTip on
Workaround:- I can get it by doing some math on TrackBar.value
Is there any better way?
Thanks in Advance... 
|
|
|
|
|
There is no direct way to do it - math is all you have, but it's not too complex.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I am trying to draw lines using below code
graphic.DrawLines(new Pen(Color.Red), pointarray);
pointarray size is 3852, I am getting overflow exception, Is there any limit to pass pointarray in DrawLines method.
Please describe...
|
|
|
|
|
Offhand, you could check if all the values are appropriate - maybe one of the values in the array are incorrect.
|
|
|
|
|
|
No, there is no limit I am aware of, and a quick test says that you can use more than 3852 points anyway:
Point[] points = new Point[4096];
public frmTesting()
{
InitializeComponent();
Random r = new Random();
for (int i = 0; i < points.Length; i++)
{
points[i] = new Point(r.Next(0, 200), r.Next(0, 200));
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Pen p = Pens.Red;
e.Graphics.DrawLines(p, points);
}
Works with no problems. I would suspect the problem is in your other code.
BTW: You shouldn't create a new Pen like that - you are responsible for calling Dispose on all graphics elements you create, so you should keep a reference to it, or use a stock item as I did.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
The only limits I know of are the size of the array you're passing. It must be less than 2GB of data and be less than Int32.MaxValue (2.147 billion) elements long.
|
|
|
|
|
I received a C# 2008 console application from a contract shop to work with. The purpose of the console application is to consume data it receives from a web service. (The contract shop that wrote the web service also wrote the console application I am suppose to work with.)
My questions are the following:
1. The console application writes to a log file. The only results I can see that can come from the log file is a dos window that displays while the application is running. If this is true, can you tell me how to have the log file write to a different location?
2. When I run the console application, I sometimes see error messages that show up in the dos popup window. At first I thought the error messages came from the web service. However today I opened up an *.xsd file and I see alot of the error messages that appeared in the dos window the last few days. Thus can you tell me how to determine how the *.xsd file is wired to the application? I would like to learn how the code is called.
3. Can I step through the code that is executed from the *.xsd file? If so, how would I accomplish this task? Do I need certain debug options set?
|
|
|
|
|
|
1. I'd guess they are using TraceListeners[^]. The one you're probaly after is the TextWriterTraceListener[^]. The link has a code snippet on how to implement the TextWriterTraceListener to help get started. The first link shows how to setup a listener declaratively using the config file. This is the better way to go because you can control your listeners without recompiling the application.
2. Don't know
"You get that on the big jobs."
|
|
|
|
|
dcof wrote: I received a C# 2008 console application from a contract shop to work with
Meaning you got the executable or the code?
dcof wrote: can you tell me how to have the log file write to a different location?
That depends on how they are logging.
However you can run an app using the following which MIGHT work. There must NOT be a space between the 2 and >.
MyApp 2>ErrorFile.txt >Output.txt
dcof wrote: Thus can you tell me how to determine how the *.xsd file is wired to the application? I would like to learn how the code is called.
Obviously looking at the code would tell you.
dcof wrote: Can I step through the code that is executed from the *.xsd file?
No. You can step through the code of the application though.
|
|
|
|
|
I’m using Visual Studio 2008 and I started a Window’s Form project in C++.
I want to switch it over to C#. I realize that I will have to basically re-write the operational code, and the functionality behind the forms, but what I want to do if I can is "import" the form designs to C#.
I’m only interested in the placement of the boxes and buttons etc., not the coding that links one form to the next or the operational code behind each button.
Is there an easy way to copy / import the forms from C++ to C#?
|
|
|
|
|
Since it is a Windows Forms CPP project, it's easy:
Go to the C++ form in design mode.
Press CTRL+A, CTRL+C
Go to the C# form.
Press CTRL+V
Voilà!
(If it missed anything, it will be custom controls, that you need to manually add the using statements for before you paste)
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thanks for the reply Griff.
Your response was 99.9% correct!
The only thing missing was that I had to make sure that the base form (the tiny one that Visual Studio creates) was enlarged large enough to hold all that the CTRL+V was going to paste into the form.
Once I did that, everything tansferred perfectly.
Thanks again -- huge help
|
|
|
|
|
I can't think of everything!
You're welcome!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Umm Hi,
This is a question related to yesterdays "Blank lines in a rich text box from a Serial Device, am I getting rid of them correctly....." I have found an oddity with the data I am reading in at odd times I get "\n" appearing (it's serial data) I am using a foreach() loop to split up the data coming in with one one the delimiters being "\n" I'm guessing that as there are two next to each other it see one kills it and lets the other pass,
Resulting in a blank line. If I use
if (subString == "\n")
break;
with out effect
I have got it so it creates the a save file as
Quote: 8/30/2012 3:51:21 PM| LD:0002=H10003027710004940129142|
8/30/2012 3:51:21 PM||
8/30/2012 3:51:21 PM| LD:0003=H2000749724900011250077140|
What I need to do is stop the above line appearing in the save function.
The foreach to assemble the string is
foreach (string subString in Unit_Reply.Split(delimeter))
{
if (subString == "\n")
break;
if (subString.Contains("\n")||subString.Contains("\r"))
{
MessageBox.Show("ALERT!!!");
}
Unit_Reply_Modded += "\n" + dt.ToString() + "|" + subString + "|";
}
the commented out lines have been tried and found not to work (also the if Contains does nothing), I was trying to avoid using the StreamReader / Writer and BinaryReader /Writer as I am a little of how they work also I am attempting to read data from a board I read in the past with out using them.
|
|
|
|