|
This will fix the problem for Saturday-Sunday, but it will not solve for Saturday-Tuesday.
|
|
|
|
|
why not:
protected override bool checkTimepoint(DateTime timepoint, DayOfWeek from, DayOfWeek to)
{
return timepoint.DayOfWeek >= from && timepoint.DayOfWeek <= to;
}
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
because this doesn't work.
testcase:
timepoint = new DateTime(2008,5,4);//sunday, 0
from = DayOfWeek.Friday; // 5
to = DayOfWeek.Tuesday; // 2
return 0 >= 5 && 0 <= 2;
return value is 'false', but sunday is between friday and tuesday!
|
|
|
|
|
You can use the CultureInfo class to set the first day of the week.
using System.Threading;
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
So, set the first day of the week to whatever day you want, and then do your comparison.
protected override bool checkTimepoint(DateTime timepoint, DayOfWeek from, DayOfWeek to)
{
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = from;
bool inRange = timepoint.DayOfWeek >= from && timepoint.DayOfWeek <= to;
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
return inRange;
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Friday, May 2, 2008 1:26 PM
|
|
|
|
|
Huh, interesting.
I wonder how it performs in a loop.
|
|
|
|
|
If performance is an issue (in a loop), you could always wait until the loop is done and reset to the proper 1st day at that point, thus saving n calls to do it in that checkpoint function.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Just thought I'd let you know I was completely wrong.
I posted a new response to the OP with the correct solution.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
What? Say it ain't so!
|
|
|
|
|
return ( true ) ;
Every timepoint falls between some DayOfWeek X and some DayOfWeek Y.
buchstaben wrote: Thursday-Wednesday
Did you mean that?
If you want Sunday to sort higher than Saturday, then you can simply add seven to it, but you'll need to store the values as integers rather than as the provided enum values.
int x = (int) timepoint.DayOfWeek ;
int y = (int) from ;
int z = (int) to ;
x += x==0 ? 7 : 0 ;
y += y==0 ? 7 : 0 ;
z += z==0 ? 7 : 0 ;
return ( x >= y && x <= z ) ;
but that's rather ugly.
|
|
|
|
|
You can set the first day of the week to be thursday, and then the comparison would work.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Ignore my first post. This is the best way (notice no bizarre culture crap going on):
DayOfWeek from = DayOfWeek.Thursday;
DayOfWeek to = DayOfWeek.Tuesday;
DayOfWeek currentDay = DayOfWeek.Wednesday;
bool inRange = (currentDay >= from || currentDay <= to);
Notice that I'm using OR instead of AND . If you make currentDay Wednesday, inRange will be false. If you make it any other day, it will be true.
It's kind of pointless to do a Sunday-Saturday (or similar) comparison because any date will fall into the range. BTW, the comparison above also works for from=Saturday and to=Sunday.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I was just reviewing a method I wrote a few months back where I was checking to see if a value (integer) is between two others. I decided I needed more than a true/false, there are (currently) four result values:
[System.FlagsAttribute()]
public enum CheckRangeResult
{
WithinStrictRange = 0
,
Low = 1
,
High = 2
,
WithinLooseRange = 3
}
Basically; given Min, Max, and Test we expect Min to be less than Max; and Test will be Lower than Min (1), Higher than Max (2), or WithinStrictRange (0).
But, when Min is greater than Max and Test is between Min and Max, both tests are true, yielding WithinLooseRange (3).
In the case presented here, when Min is greater than Max and Test is not between the values, that should translate to "true", but that's not currently supported.
I think I need to add value 4 to indicate that Min is greater than Max, then WithinLooseRange would have value 7. I'll think about it over the weekend.
|
|
|
|
|
It occurred to me late today that this might make a good Friday Programming Quiz.
|
|
|
|
|
Maybe even two questions...
1) Given the following:
DayOfWeek startDay = DayOfWeek.Thursday;
DayOfWeek endDay = DayOfWeek.Monday;
DayOfWeek currentDay = DayOfWeek.Wednesday;
Write a C# publicly accessible function that determines whether or not the day falls between startDay and endDay . The function should work for any combination of startDay /endDay values, and should return a boolean value (true if in range, false if not in range).
Answer:
public bool DateInRange(DayOfWeek currentDay, DayOfWeek startDay, DayofWeek endDay)
{
return (currentDay >= startDay || currentDay <= endDay);
}
2) Given the function above, change the function so that the class encapsulating it does not have to be instantiated in order to use the function.
Answer:
public static bool DateInRange(DayOfWeek currentDay, DayOfWeek startDay, DayofWeek endDay)
{
return (currentDay >= startDay || currentDay <= endDay);
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I don't think that works with the "normal" case where startDay < endDay.
It's also not a very general solution (which is no crime).
Given a number (value) line, two points on that line that define a range, and another point to test inclusion.
Normal
...........
1 > 2 < 3
Inverted (endponts not in normal order)
...........
4 < 5 > 6
The test value could be in any of the spots labeled 1 - 6.
We then need to assign true/false to these spots.
Clearly 2 yields true, while 1 and 3 yield false.
The question is about the inverted range;
The OP needs to assign true to 4 and 6, false to 5.
The code I wrote in November was designed to allow assigning true to 5, false to 4 and 6.
I have now modified my helper method (and enum) so it returns one of six values (it was four previously).
The application then needs to provide a method that handles the translation to true/false.
|
|
|
|
|
I think this should cover it then...
public static void DayInRange(DayOfWeek currentDay, DayOfWeek startDay, DayOfWeek endDay)
{
if (startDay == endDay)
{
return true;
}
if (startDay < endDay)
{
return (currentDay >= startDay && currentDay <= endDay);
}
return (currentDay >= startDay || currentDay <= endDay);
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
That hurts my eyes.
(Not that I should talk. )
|
|
|
|
|
On keypress event i am disallow some of the some of the ascii value
like this
if (((e.KeyChar >= 91 && e.KeyChar <= 96) || e.KeyChar == 123 || e.KeyChar == 124 || e.KeyChar == 125 || e.KeyChar == 42 || e.KeyChar == 33 || e.KeyChar == 35 || e.KeyChar == 38 || e.KeyChar == 40 || e.KeyChar == 39 || e.KeyChar == 34 || e.KeyChar == 41 || e.KeyChar == 44 || e.KeyChar == 64 || e.KeyChar == 61 || e.KeyChar == 59 || e.KeyChar == 58 || e.KeyChar == 63 || e.KeyChar == 60 || e.KeyChar == 62) != false)<br />
{<br />
e.Handled = true;<br />
<br />
}
Now hat i want when user press space bar (Ascii value 32) then it will print '~' (Ascii value 126) in place of Ascii 32
if user enter
ABCD(SPACE)FGT THEN IT SHOULD PRINT
ABCD~FGT
|
|
|
|
|
Hi,
You may use the following code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Space Then
e.SuppressKeyPress = True
Dim i As Integer
i = Me.TextBox1.SelectionStart
Me.TextBox1.Text = Me.TextBox1.Text + "~"
Me.TextBox1.SelectionStart = i + 1
End If
End Sub
Hope this helps.
Vinay
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Will this work?
if ( e.KeyChar == ' ' ) e.KeyChar = '~' ;
And the code you posted looks very difficult to maintain.
|
|
|
|
|
Well no offense...but the code above is VB
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
No it isn't. Why do you say so? Or do you mean Vinay's response?
|
|
|
|
|
second option:
PIEBALDconsult wrote: Vinay's response
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
Hi guys. I need some help with the below.
foreach (CsvImp imp in res)
{
string prov = SearchPcode(imp.CallComments);
txtboxDisplay.Text += imp.CompanyCode + "\t" + imp.CallComments.ToString()
+ "\t" + prov + Environment.NewLine;
engine.WriteFile(@"C:\Sasol_" + DateTime.Today.ToString("ddMMyyyyhhmm") + ".csv", res);
}
I am reading in a file with FileHelpers and writing some of the fields to a text box. I am also using one of the imported fields and matching that to derive an extra field which I am able to write to the textbox as well. Now, my problem is when I use the FileHelper engine to write to file I can only write the data in the res . I need to write all that data plus the extra field prov to file.
Any idea how I do that? Or any other suggestions??
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Kwagga wrote: file with FileHelpers
I don't know what that is.
Kwagga wrote: I am also using one of the imported fields and matching that to derive an extra field
I don't know what this means.
Kwagga wrote: I need to write all that data plus the extra field prov to file.
Maybe I'm misunderstanding what you're asking, but shouldn't this work?
engine.WriteFile(@"C:\Sasol_" + DateTime.Today.ToString("ddMMyyyyhhmm") + ".csv", res + Environment.NewLine + prov);
|
|
|
|