|
robmays wrote:
I was hoping someone may have a formula already sorted
What you mean: DayOfYear / 7
robmays wrote:
I was being lazy
It sure looks like it from here.
robmays wrote:
can't life be that simple?
"Life is tough, but if you're tough on yourself, then life is so much easier on YOU!" -- Zig Ziglar
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
no not that one bit mor complicated here is one for someone if needed
// Static Method to return WeekNumber (1-53) for a given year
public static int WeekNumber(DateTime dt) {
// Set Year
int yyyy=dt.Year;
// Set Month
int mm=dt.Month;
// Set Day
int dd=dt.Day;
// Declare other required variables
int DayOfYearNumber;
int Jan1WeekDay;
int WeekNumber=0, WeekDay;
int i,j,k,l,m,n;
int[] Mnth = new int[12] {0,31,59,90,120,151,181,212,243,273,304,334};
int YearNumber;
// Set DayofYear Number for yyyy mm dd
DayOfYearNumber = dd + Mnth[mm-1];
// Increase of Dayof Year Number by 1, if year is leapyear and month is february
if ((IsLeapYear(yyyy) == true) && (mm == 2))
DayOfYearNumber += 1;
// Find the Jan1WeekDay for year
i = (yyyy - 1) % 100;
j = (yyyy - 1) - i;
k = i + i/4;
Jan1WeekDay = 1 + (((((j / 100) % 4) * 5) + k) % 7);
// Calcuate the WeekDay for the given date
l= DayOfYearNumber + (Jan1WeekDay - 1);
WeekDay = 1 + ((l - 1) % 7);
// Find if the date falls in YearNumber set WeekNumber to 52 or 53
if ((DayOfYearNumber <= (8 - Jan1WeekDay)) && (Jan1WeekDay > 4))
{
YearNumber = yyyy - 1;
if ((Jan1WeekDay == 5) || ((Jan1WeekDay == 6) && (Jan1WeekDay > 4)))
WeekNumber = 53;
else
WeekNumber = 52;
}
else
YearNumber = yyyy;
// Set WeekNumber to 1 to 53 if date falls in YearNumber
if (YearNumber == yyyy)
{
if (IsLeapYear(yyyy)==true)
m = 366;
else
m = 365;
if ((m - DayOfYearNumber) < (4-WeekDay))
{
YearNumber = yyyy + 1;
WeekNumber = 1;
}
}
if (YearNumber==yyyy) {
n=DayOfYearNumber + (7 - WeekDay) + (Jan1WeekDay -1);
WeekNumber = n / 7;
if (Jan1WeekDay > 4)
WeekNumber -= 1;
}
return (WeekNumber);
}
|
|
|
|
|
Nice work, but why don't you use properties of the structure DateTime? Some of them i even mentioned in my first comment. I think this could at least spare you some lines of code and therefor increase readibility.
For example you wrote:
DayOfYearNumber = dd + Mnth[mm-1];<br />
<br />
l= DayOfYearNumber + (Jan1WeekDay - 1);<br />
WeekDay = 1 + ((l - 1) % 7);
Alternativ:
DayOfYearNumber = dt.DayOfYear;<br />
<br />
l = dt.DayOfWeek;
|
|
|
|
|
robmays wrote:
// Set DayofYear Number for yyyy mm dd
DayOfYearNumber = dd + Mnth[mm-1];
// Increase of Dayof Year Number by 1, if year is leapyear and month is february
if ((IsLeapYear(yyyy) == true) && (mm == 2))
DayOfYearNumber += 1;
The result of this calculation will be wrong for any date from the 1st February onwards on a leap year. You will increase the DayOfYearNumber on a leap year if the month is February (before the leap day occurs), but not for the remainder of the months in the year (after the leap day).
try:
if ((IsLeapYear(yyyy)) && (mm > 2))
DayOfYearNumber++;
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
Why don't you use System.Globalization.GregorianCalendar object which has GetWeekOfYear method : -
public static int WeekNumber(DateTime dt)
{
System.Globalization.GregorianCalendar gCal=new System.Globalization.GregorianCalendar();
return gCal.GetWeekOfYear(dt,System.Globalization.CalendarWeekRule.FirstDay,System.DayOfWeek.Monday);
}
Cheers
Never comment ur code. If it was hard to write, it should be hard to understand !!!
|
|
|
|
|
Life can be so simple.
The framework has a method for almost everything, you just need to find it
|
|
|
|
|
well since i have been too lunch i think i have had my 5 min of fame, glad to have stirred a few pro developers, i am a newbee like the look of the globalization near the end i will look into that one BUT in the ned i got my easy life so as i concentrate on the bigger picture.;);)
|
|
|
|
|
robmays wrote:
i have had my 5 min of fame
Well, according to Andy Worhole you get another 10 minutes.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
There's no good excuse for not reading the .NET Framework SDK documentation. Reading documentation is one thing that separates the developers from the code monkeys.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok ,ive started on my page class so you know what my weekend will be like. i ve started by adding a new class to the project called pgeHeating:TabPage is that correct so far with the inheritance
|
|
|
|
|
Yes, but use the .NET naming conventions. Keeping with the naming conventions is important to maintain a common convention through an application and the Framework. A better name would be something like HeatingPage . Just look at how the classes and members are named throughout the .NET FCL.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
|
soory if i was a bit different as it is uk time on a friday i started on the red wine hoefully i will have proceeded with my class over the weekend it has been agreat week thanks to you
|
|
|
|
|
been at since 5 am when creating my page class to get access to all my text values so as i can add them to a database it seem that all the controls i add to my page need to be public then i can see them when i add the page to my tab control. goes against encapsulation????
|
|
|
|
|
It's a far better OO design where the property sheet (or that which opens it) passes a DataSet or something to each TabPage derivative (helps to extend your own base class or implement some custom interface so you can abstractly work with each class) and let them perform the necessary operations. What you're doing now is still pretty inflexible since each TabPage derivative is highly coupled with your property sheet (the form with the TabControl ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
first error:
method system.windows.forms.tabpage.schemes not found
then lots of:
operation not valid due to the current state of the object?
whole load of them in the task list when i switch my class to design view?
have i missed some designer specific code?
|
|
|
|
|
If your tab pages are in a different namespace, then you need to import that namespace using the using Namespace; statement like you do with every other class.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
the project is called 'Patriot' so all namespaces are the same as the classes have been created in the same project
|
|
|
|
|
The project name doesn't mean anything, except that the default root namespace is the project name. If you use folders in your project, source files added to those folders are defaulted to the root namespace plus the folder name(s) appended in hierarchical order. Just look at the source files to see what namespace they're in.
Also, do not make a namespace for each separate class! C'mon, think about it. Does each control in System.Windows.Forms have a separate namespace? No, they're all grouped into that namespace. Namespaces are there to logically group classes and other members, just like System includes all the ubiquitous stuff, and System.Data includes all the core ADO.NET classes, and System.Web includes all the core ASP.NET class while System.Web.UI.WebControls includes a bunch of web controls.
If your current class is in a different namespace, then you must import all namespaces that are different - regardless of whether or not they're in your current project! - or you must type in their fully-qualified type name (namespace + class/interface/struct/enum name).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
what source files are you talking about? im working hard on the namespaces as icant see it yet
|
|
|
|
|
The files that contain your source code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
yes and they all are using the same namespace ie 'patriot' the problem is only there for my tabpages and when i look at my new tabpage in the deign view the controls look a mess, but comes out perfect when i run the project
|
|
|
|
|
i know you are very busy man, but i hope you have not deserted me
|
|
|
|
|
ive checked and there is only on namespace, but i have lots of errors like
method not found
operation is not valid
the variable fixedsingle is either undeclared or was never used
etc
|
|
|
|