G
Guest
Could someone please help me converting the following lines of vb6 code to
vb.net. The message box should display "1/3/2005" if it is executed today.
Private Sub Form_Load()
Dim nWeekNumber As Integer
Dim ThisYearStart As Date
ThisYearStart = YearStart(Today, 2)
msgbox ThisYearStart
End Sub
Function YearStart(WhichYear As Integer) As Date
Dim WeekDay As Integer
Dim NewYear As Date
NewYear = DateSerial(WhichYear, 1, 1)
WeekDay = (NewYear - 2) Mod 7
If WeekDay < 4 Then
YearStart = NewYear - WeekDay
Else
YearStart = NewYear - WeekDay + 7
End If
End Function
vb.net. The message box should display "1/3/2005" if it is executed today.
Private Sub Form_Load()
Dim nWeekNumber As Integer
Dim ThisYearStart As Date
ThisYearStart = YearStart(Today, 2)
msgbox ThisYearStart
End Sub
Function YearStart(WhichYear As Integer) As Date
Dim WeekDay As Integer
Dim NewYear As Date
NewYear = DateSerial(WhichYear, 1, 1)
WeekDay = (NewYear - 2) Mod 7
If WeekDay < 4 Then
YearStart = NewYear - WeekDay
Else
YearStart = NewYear - WeekDay + 7
End If
End Function