VB6 to VB.Net Conversion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shariq

    VB6 to VB.Net Conversion

    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(Which Year As Integer) As Date
    Dim WeekDay As Integer
    Dim NewYear As Date
    NewYear = DateSerial(Whic hYear, 1, 1)
    WeekDay = (NewYear - 2) Mod 7
    If WeekDay < 4 Then
    YearStart = NewYear - WeekDay
    Else
    YearStart = NewYear - WeekDay + 7
    End If
    End Function


  • Lior Bobrov

    #2
    Re: VB6 to VB.Net Conversion

    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 .


    "Shariq" <Shariq@discuss ions.microsoft. com> wrote in message
    news:E47DFB58-2511-4AAF-B979-4FD1C6C349E2@mi crosoft.com...[color=blue]
    > 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(Which Year As Integer) As Date
    > Dim WeekDay As Integer
    > Dim NewYear As Date
    > NewYear = DateSerial(Whic hYear, 1, 1)
    > WeekDay = (NewYear - 2) Mod 7
    > If WeekDay < 4 Then
    > YearStart = NewYear - WeekDay
    > Else
    > YearStart = NewYear - WeekDay + 7
    > End If
    > End Function
    >
    >[/color]


    Comment

    • Cor Ligthert

      #3
      Re: VB6 to VB.Net Conversion

      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


      Comment

      • Shariq

        #4
        RE: VB6 to VB.Net Conversion

        The following VB.Net code was converted from VB6 but I am unable to resolve
        the errors it generate when code is executed. It suppose to generate ISO Week
        and Year number for a given date; VB6 code works fine.

        Private Sub Form1_Load(ByVa l eventSender As System.Object, ByVal eventArgs
        As System.EventArg s) Handles MyBase.Load
        Dim sNewWeek As Object
        Dim sNewYear As String

        sDBPath = "C:\STIApps\STL abels\TIC\Data\ TIC_Data.mdb, 0"
        Text1.Text = CStr(Today)
        'UPGRADE_WARNIN G: Couldn't resolve default property of object sNewWeek.
        Click for more:
        'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1037 "'
        sNewWeek = txtISOWeek.Text
        sNewYear = txtISOYear.Text
        End Sub

        Private Sub cmdExit_Click(B yVal eventSender As System.Object, ByVal
        eventArgs As System.EventArg s) Handles cmdExit.Click
        End
        End Sub

        Private Sub Command1_Click( ByVal eventSender As System.Object, ByVal
        eventArgs As System.EventArg s) Handles Command1.Click
        Dim dteDate As Date
        dteDate = CDate(Text1.Tex t)
        Text2.Text = CStr(ISOWeekNum (dteDate, 2))
        Text2.Text = VB6.Format(Text 2.Text, "0000")
        txtISOWeek.Text = VB.Right(Text2. Text, 2)
        txtISOYear.Text = VB.Left(Text2.T ext, 2)
        End Sub

        Public Function ISOWeekNum(ByRe f AnyDate As Date, Optional ByRef
        WhichFormat As Object = Nothing) As Short
        Dim ThisYear As Short
        Dim PreviousYearSta rt As Date
        Dim ThisYearStart As Date
        Dim NextYearStart As Date
        Dim YearNum As Short

        ThisYear = Year(AnyDate)
        ThisYearStart = YearStart(ThisY ear)

        PreviousYearSta rt = YearStart(ThisY ear - 1)
        NextYearStart = YearStart(ThisY ear + 1)
        Select Case AnyDate
        Case Is >= NextYearStart
        ISOWeekNum = (AnyDate.ToOADa te - NextYearStart.T oOADate) \ 7 + 1
        YearNum = Year(AnyDate) + 1
        Case Is < ThisYearStart
        ISOWeekNum = (AnyDate.ToOADa te - PreviousYearSta rt.ToOADate) \ 7 + 1
        YearNum = Year(AnyDate) - 1
        Case Else
        ISOWeekNum = (AnyDate.ToOADa te - ThisYearStart.T oOADate) \ 7 + 1
        YearNum = Year(AnyDate)
        End Select

        'UPGRADE_NOTE: IsMissing() was changed to IsNothing(). Click for more:
        'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1021 "'
        If IsNothing(Which Format) Then
        Exit Function
        End If
        Dim nYear As Short
        'UPGRADE_WARNIN G: Couldn't resolve default property of object WhichFormat.
        Click for more:
        'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1037 "'
        If WhichFormat = 2 Then
        ISOWeekNum = CShort(VB6.Form at(VB.Right(CSt r(YearNum), 2), "00") &
        VB6.Format(ISOW eekNum, "00"))
        End If
        End Function


        Function YearStart(ByRef WhichYear As Short) As Date
        'UPGRADE_NOTE: WeekDay was upgraded to WeekDay_Renamed . Click for more:
        'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1061 "'
        Dim WeekDay_Renamed As Object
        Dim x As Short
        Dim NewYear As Date

        NewYear = DateSerial(Whic hYear, 1, 1)
        'UPGRADE_WARNIN G: Couldn't resolve default property of object
        WeekDay_Renamed . Click for more:
        'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1037 "'
        WeekDay_Renamed = System.Date.Fro mOADate(NewYear .ToOADate - 2).ToOADate
        Mod 7
        'UPGRADE_WARNIN G: Couldn't resolve default property of object
        WeekDay_Renamed . Click for more:
        'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1037 "'
        If WeekDay_Renamed < 4 Then
        YearStart = System.Date.Fro mOADate(NewYear .ToOADate -
        CDate(WeekDay_R enamed).ToOADat e)
        Else
        YearStart = System.Date.Fro mOADate(NewYear .ToOADate -
        CDate(WeekDay_R enamed).ToOADat e + 7)
        End If
        End Function

        "Shariq" wrote:
        [color=blue]
        > 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(Which Year As Integer) As Date
        > Dim WeekDay As Integer
        > Dim NewYear As Date
        > NewYear = DateSerial(Whic hYear, 1, 1)
        > WeekDay = (NewYear - 2) Mod 7
        > If WeekDay < 4 Then
        > YearStart = NewYear - WeekDay
        > Else
        > YearStart = NewYear - WeekDay + 7
        > End If
        > End Function
        >
        >[/color]

        Comment

        • Cor Ligthert

          #5
          Re: VB6 to VB.Net Conversion

          Shariq,

          We know, however see by instance by Stephanie, probably is it easier to make
          the code when you tell what you want as result.

          Cor


          Comment

          • Shariq

            #6
            RE: VB6 to VB.Net Conversion

            All I need is to know how to calculate ISO Week number; Is there anything
            available in VB.Net or any references/links to it?


            "Shariq" wrote:
            [color=blue]
            > 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(Which Year As Integer) As Date
            > Dim WeekDay As Integer
            > Dim NewYear As Date
            > NewYear = DateSerial(Whic hYear, 1, 1)
            > WeekDay = (NewYear - 2) Mod 7
            > If WeekDay < 4 Then
            > YearStart = NewYear - WeekDay
            > Else
            > YearStart = NewYear - WeekDay + 7
            > End If
            > End Function
            >
            >[/color]

            Comment

            • Cor Ligthert

              #7
              Re: VB6 to VB.Net Conversion

              Shariq,

              There is a method to find the week.


              However see as well this where is described that it does not produce the
              correct ISO 8601 weeknumbers. I don't know if that is important.



              I hope this helps anyway something

              Cor


              Comment

              • james

                #8
                Re: VB6 to VB.Net Conversion

                Shariq, not sure if this is what you are wanting, but, how about something like this:


                Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

                MsgBox("Today's Date=" & " " & Date.Now.ToShor tDateString)

                End Sub


                Put a single button on a form and insert : MsgBox("Today's Date=" & " " & Date.Now.ToShor tDateString)

                this will popup a MessageBox with today's date in the format you seem to be wanting. ( 4/18/2005)
                From there you can get other days in the same format.
                HTH
                james



                "Shariq" <Shariq@discuss ions.microsoft. com> wrote in message news:09BD9ABE-8DEB-4BF4-88F8-263FD096357D@mi crosoft.com...[color=blue]
                > All I need is to know how to calculate ISO Week number; Is there anything
                > available in VB.Net or any references/links to it?
                >
                >
                > "Shariq" wrote:
                >[color=green]
                >> 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(Which Year As Integer) As Date
                >> Dim WeekDay As Integer
                >> Dim NewYear As Date
                >> NewYear = DateSerial(Whic hYear, 1, 1)
                >> WeekDay = (NewYear - 2) Mod 7
                >> If WeekDay < 4 Then
                >> YearStart = NewYear - WeekDay
                >> Else
                >> YearStart = NewYear - WeekDay + 7
                >> End If
                >> End Function
                >>
                >>[/color][/color]


                Comment

                • james

                  #9
                  Re: VB6 to VB.Net Conversion

                  Ignore my silly answer!!!

                  If I had read your original post correctly, I would see that my answer is not what you are looking for.
                  I think Cor's answer is probably what you want.
                  james


                  "james" <jjames700ReMoV eMe at earthlink dot net> wrote in message news:%23HSfjcER FHA.3928@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                  > Shariq, not sure if this is what you are wanting, but, how about something like this:
                  >
                  >
                  > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
                  >
                  > MsgBox("Today's Date=" & " " & Date.Now.ToShor tDateString)
                  >
                  > End Sub
                  >
                  >
                  > Put a single button on a form and insert : MsgBox("Today's Date=" & " " & Date.Now.ToShor tDateString)
                  >
                  > this will popup a MessageBox with today's date in the format you seem to be wanting. ( 4/18/2005)
                  > From there you can get other days in the same format.
                  > HTH
                  > james
                  >[/color]


                  Comment

                  • Shariq

                    #10
                    Re: VB6 to VB.Net Conversion

                    The link you provided http://konsulent.sandelien.no/VB_help/Week/
                    has a corrected version of the code that prints the correct ISO week number
                    but it is in C#.Net. How do I convert it to VB.Net?

                    "Cor Ligthert" wrote:
                    [color=blue]
                    > Shariq,
                    >
                    > There is a method to find the week.
                    > http://msdn.microsoft.com/library/de...fyeartopic.asp
                    >
                    > However see as well this where is described that it does not produce the
                    > correct ISO 8601 weeknumbers. I don't know if that is important.
                    >
                    > http://konsulent.sandelien.no/VB_help/Week/
                    >
                    > I hope this helps anyway something
                    >
                    > Cor
                    >
                    >
                    >[/color]

                    Comment

                    • Shariq

                      #11
                      RE: VB6 to VB.Net Conversion

                      I thank you all for your support and help.
                      Finally I was able to get my code to work and produce the correct ISO Week
                      numbers. Please let me know if anyone needing the code.

                      "Shariq" wrote:
                      [color=blue]
                      > 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(Which Year As Integer) As Date
                      > Dim WeekDay As Integer
                      > Dim NewYear As Date
                      > NewYear = DateSerial(Whic hYear, 1, 1)
                      > WeekDay = (NewYear - 2) Mod 7
                      > If WeekDay < 4 Then
                      > YearStart = NewYear - WeekDay
                      > Else
                      > YearStart = NewYear - WeekDay + 7
                      > End If
                      > End Function
                      >
                      >[/color]

                      Comment

                      • james

                        #12
                        Re: VB6 to VB.Net Conversion


                        "Shariq" <Shariq@discuss ions.microsoft. com> wrote in message news:7B39BEAB-4BFC-449A-8038-6FCE366CB2B4@mi crosoft.com...[color=blue]
                        >I thank you all for your support and help.
                        > Finally I was able to get my code to work and produce the correct ISO Week
                        > numbers. Please let me know if anyone needing the code.
                        >[/color]

                        It would be interesting to see how you finally got it working.
                        james


                        Comment

                        • S i m e n  S a n d e l i e n

                          #13
                          Re: VB6 to VB.Net Conversion

                          Hi Shariq!

                          It shouldn't be too difficult to port the code to VB.NET. If I find the time
                          I'll post a VB.NET version as well. If you're serious about getting ISO week
                          numbers you should use the algorithm shown.

                          sincerely,
                          Simen

                          "Shariq" wrote:
                          [color=blue]
                          > The link you provided http://konsulent.sandelien.no/VB_help/Week/
                          > has a corrected version of the code that prints the correct ISO week number
                          > but it is in C#.Net. How do I convert it to VB.Net?
                          >
                          > "Cor Ligthert" wrote:
                          >[color=green]
                          > > Shariq,
                          > >
                          > > There is a method to find the week.
                          > > http://msdn.microsoft.com/library/de...fyeartopic.asp
                          > >
                          > > However see as well this where is described that it does not produce the
                          > > correct ISO 8601 weeknumbers. I don't know if that is important.
                          > >
                          > > http://konsulent.sandelien.no/VB_help/Week/
                          > >
                          > > I hope this helps anyway something
                          > >
                          > > Cor
                          > >
                          > >
                          > >[/color][/color]

                          Comment

                          Working...