|
my hint was 365 and 366, not your 364 and 365 day ...
<br />
Private Function Weeknumber_Entire4DayWeekRule(ByVal inDate As DateTime) As Integer<br />
Const JAN As Integer = 1<br />
Const DEC As Integer = 12<br />
Const LASTDAYOFDEC As Integer = 31<br />
Const FIRSTDAYOFJAN As Integer = 1<br />
Const THURSDAY As Integer = 4<br />
Dim ThursdayFlag As Boolean = False<br />
<br />
' Get the day number since the beginning of the year<br />
Dim DayOfYear As Integer = inDate.DayOfYear<br />
<br />
' Get the numeric weekday of the first day of the<br />
' year (using sunday as FirstDay)<br />
Dim StartWeekDayOfYear As Integer = _<br />
DirectCast(New DateTime(inDate.Year, JAN, FIRSTDAYOFJAN).DayOfWeek, Integer)<br />
Dim EndWeekDayOfYear As Integer = _<br />
DirectCast(New DateTime(inDate.Year, DEC, LASTDAYOFDEC).DayOfWeek, Integer)<br />
<br />
' Compensate for the fact that we are using monday<br />
' as the first day of the week<br />
If StartWeekDayOfYear = 0 Then<br />
StartWeekDayOfYear = 7<br />
End If<br />
If EndWeekDayOfYear = 0 Then<br />
EndWeekDayOfYear = 7<br />
End If<br />
<br />
' Calculate the number of days in the first and last week<br />
Dim DaysInFirstWeek As Integer = 8 - StartWeekDayOfYear<br />
Dim DaysInLastWeek As Integer = 8 - EndWeekDayOfYear<br />
<br />
' If the year either starts or ends on a thursday it will have a 53rd week<br />
If StartWeekDayOfYear = THURSDAY OrElse EndWeekDayOfYear = THURSDAY Then<br />
ThursdayFlag = True<br />
End If<br />
<br />
' We begin by calculating the number of FULL weeks between the start of the year and<br />
' our date. The number is rounded up, so the smallest possible value is 0.<br />
Dim FullWeeks As Integer = _<br />
CType(Math.Ceiling((DayOfYear - DaysInFirstWeek) / 7), Integer)<br />
<br />
Dim WeekNumber As Integer = FullWeeks<br />
<br />
' If the first week of the year has at least four days, then the actual week number for our date<br />
' can be incremented by one.<br />
If DaysInFirstWeek >= THURSDAY Then<br />
WeekNumber = WeekNumber + 1<br />
End If<br />
<br />
' If week number is larger than week 52 (and the year doesn't either start or end on a thursday)<br />
' then the correct week number is 1.<br />
If WeekNumber > 52 AndAlso Not ThursdayFlag Then<br />
WeekNumber = 1<br />
End If<br />
<br />
'If week number is still 0, it means that we are trying to evaluate the week number for a<br />
'week that belongs in the previous year (since that week has 3 days or less in our date's year).<br />
'We therefore make a recursive call using the last day of the previous year.<br />
If WeekNumber = 0 Then<br />
WeekNumber = Weeknumber_Entire4DayWeekRule( _<br />
New DateTime(inDate.Year - 1, DEC, LASTDAYOFDEC))<br />
End If<br />
Return WeekNumber<br />
End Function
i found this with google: "week number vb.net"
|
|
|
|
|
You are only going to have 52 weeks, plus one (or two, if leap year) additional day(s)... so what you will need to know is what day the additional day(s) is/are, which should be easy to find if you know what day 1 Jan of that year is.
Or have I totally misunderstood what you want?
|
|
|
|
|
yes this would be true if there was only 1 way the weeknumbers are calculated in the world but as it stands there are 3 major ways and these then have different ways that need to be calculated still
let me explain a bit more
in the world there are 3 kind of weeksystems
- week 1 is where 1/1/YYYY fals into
- week 1 is the first week of the year that has 4 full days in the new year
- week 1 is the first full week of the new year
and then there is also the posibility that the week starts at a different day
usually its monday but on occasion its sunday (or in extreem cases any other day)
say 1/1/2008 is a thuesday (as it is now) then 2007 has 52 weeks (if start of week = monday or sunday)
say 1/1/2008 is a thursday (as 3/1/2008 is now) then 2007 has 52 weeks if start of week = monday but has 53 weeks if start of week = sunday
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
I believe all of the above can be achieved if you know the day that 1 Jan falls on...
I am not aware of any direct function call, however - you will need to write it on your own, maybe with switch statements.
|
|
|
|
|
ChandraRam wrote: I am not aware of any direct function call
I was afraid of that
thanks anyway
when I'v written it I'll post it here or as an article since I think this is something many other people might encounter
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
Hi all,
I am using the following API call to get the Icons and Type of windows file in my application.
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
(ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, _
ByVal uFlags As Integer) As IntPtr
To get the FIle Type from the above function i needed to include this line:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
in the strcuture declaration.
This works good in my machine, and returns me the icon and FIle Type. But when i take this code to a different machine, it gives me a build error:
'Charset' is not accessible in this context because it is private.
Can anyone help me figure out as what can be the cause of the problem, as its creating a problem in my developement environment where i use Source Safe to merge everyones work.
Thanks ,
Hemesh
|
|
|
|
|
I don't have any idea why it's throwing that exception, but you don't even need your CharSet value. In VB.NET, CharSet is Auto by default. In C#, it's Ansi.
There are really only two settings anyway. Under Windows 9x and Me, the Auto setting will pick Ansi. Under everything else, Auto picks Unicode.
Though, you still need the Sequential LayoutKind...
|
|
|
|
|
Thanks Dave,
You are right. Its an optional Param. I dont ned to mention the value to be Auto. But if i dont do it, i will not be able to get back the Type of File from the Function. It returns a Blank String. I specifically have to mention the charset for that.
Please refere to the following article for reference:
http://www.thescripts.com/forum/thread365827.html
|
|
|
|
|
Hi
I use Access database in my vb.net project. when I run program in debug mode I get correct display of date time value in a table of a table adapter I use.
The form of displayed value is supposed to be short date ( ex. 4.1.2008 ). but when I run the program as an independent program then the value is diplayed with time like 4.1.2008 10:35.
Does anyone know how to resolve this problem.
Bye
|
|
|
|
|
I found the error but thanks anyway.
|
|
|
|
|
Hi Borec,
How do you solve this issue? I'm also facing something similar. Don't mind to tell us how you solve it?
thanks.
telly
|
|
|
|
|
kindly give the soluton you found.
thanks,
Madhav
|
|
|
|
|
Never mind... i found the problem... it was a security issue
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
modified on Friday, January 04, 2008 4:59:06 AM
|
|
|
|
|
Hi
I m developing an internet explore. i m using webbrowser control for navigating the web sites. I m facing problems for blocking the popups windows... Can anybody tell me how to block the popup windows when using webbrowser control in vb.net. Thx in advance
King
|
|
|
|
|
Putting a webbrowser in a form and thinking you wrote a browser seems to be a common pursuit. I am not sure you can do much to block popups without writing a browser plug in. In any case, IE does a fine job of blocking popups, at least with the google toolbar installed, it does.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I need to communicate with an sd card thru VB.net how can I do that? any suggestions?
BiG RaLpH
|
|
|
|
|
U can directly connect by using ports and device I/O
You do not have to directly connect to the card reader..
The card reader comes with a SDK and driver interface which lets u do it..
Good Luck
|
|
|
|
|
thx for ur help but the card reader is a USB Device.
what can I do?
thx again
BiG RaLpH
|
|
|
|
|
Dose it not have a SDK along..
I had connected with a smart card not with SD card...
i hope the SDK will do the trick
The long way is identify the device ID given by OS and try to connect..
I am not having any samples to give ... sorry for that..
I had connected to a Tablet with the tablet dll available in the SDK..
Thats all i can tell u..
|
|
|
|
|
Thx I will try it.
I will let u know if it works.
BiG RaLpH
|
|
|
|
|
You can't communicate with the card. It's considered media, not a device.
The card read/write is the device.
But that's neither here nor there. When inserted, the contents of the card will be exposed as part of the file system, usually a FAT32 volume. You can use any of the normal file/volume operations to get at the card.
|
|
|
|
|
I want to read it as a binary file all of it this will help me get to where i want in the file.
any Ideas on how to do that?
thx a lot.
BiG RaLpH
|
|
|
|
|
Use the normal I/O operation to read the file inside the SD. Use the object File under the namespace System.IO
Byez
|
|
|
|
|
Hello every one
Can any one plz let me know how to find the row index of selected cell / current cell
I have to add some text in the current or selected row's specific column once the index of the combobox (outside the grid) is changed by the user.
Regards
Nishkarsh
|
|
|
|
|
If you are using a DataGridView or something similar you can usually access the SelectedCells() property. SelectedCells(0).RowIndex gives you the row index of the first selected cell.
Volker Weichert
|
|
|
|