|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB6 to VB.Net Conversionvb.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 Why not using the Upgrade Wizard of Visual Studio .NET ?
You can use it to convert VB6 to VB.NET project . Simply put your code in a VB6 project , save it and follow the steps of the upgrade wizard of Visual Studio .NET . Good luck , Lior . Show quoteHide quote "Shariq" <Sha***@discussions.microsoft.com> wrote in message news:E47DFB58-2511-4AAF-B979-4FD1C6C349E2@microsoft.com... > 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 > > Shariq,
In addition to Lior, When you use VB2003 than you can open Tools->Upgrade VB6 code paste it in, and the code will be set changed in your current class. However, I think that you not should use this code. You want to translate the date Now (15-1-2005) into 1/3/2005, what date is 1/3/2005. In the US and English Canada this means January 3 2005, in most other countries it means 1 March 2005. So give us first an idea what you mean with that date. Cor The issue is to determine the date of the Monday of the first week in which
contains 4 or more days of the year. Try this: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show(YearStart(DateTime.Now)) End Sub Private Function YearStart(ByRef CheckDate As DateTime) As DateTime Dim _firstmonday As DateTime = New DateTime(CheckDate.Year, 1, 1) Do Until _firstmonday.DayOfWeek = DayOfWeek.Monday _firstmonday = _firstmonday.AddDays(1) Loop If _firstmonday.Day < 5 Then _firstmonday = _firstmonday.AddDays(-7) Return _firstmonday End Function The first step is to determine the first Monday of the year of interest. This is achieved by a simple loop. It is also, probably, achievable by an equation. If the 'date' of the first Monday is prior to the 5th of January then there are less than 4 days of the new year in the previous week so we must return the date of the previous Monday instead. If one considers Sunday to be the first day of the week (instead of monday) then simply the loop comparator to read 'DayOfWeek.Sunday'. Show quoteHide quote "Shariq" <Sha***@discussions.microsoft.com> wrote in message news:E47DFB58-2511-4AAF-B979-4FD1C6C349E2@microsoft.com... > 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 > >
Why use a module instead of class?
An absence of IntelliSense in this situation Making trial version How to overload method of third party component? creating an array as property of a class Question about Namespaces and the Object Browser. Limiting the directories somebody can browse to..... Creating a custom log Hierarchal recordset Passing parameters to Data Adapter |
|||||||||||||||||||||||