471,596 Members | 860 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

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(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
Nov 21 '05 #1
12 4428
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" <Sh****@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.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

Nov 21 '05 #2
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
Nov 21 '05 #3
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(ByVal eventSender As System.Object, ByVal eventArgs
As System.EventArgs) Handles MyBase.Load
Dim sNewWeek As Object
Dim sNewYear As String

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

Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles cmdExit.Click
End
End Sub

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

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

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

PreviousYearStart = YearStart(ThisYear - 1)
NextYearStart = YearStart(ThisYear + 1)
Select Case AnyDate
Case Is >= NextYearStart
ISOWeekNum = (AnyDate.ToOADate - NextYearStart.ToOADate) \ 7 + 1
YearNum = Year(AnyDate) + 1
Case Is < ThisYearStart
ISOWeekNum = (AnyDate.ToOADate - PreviousYearStart.ToOADate) \ 7 + 1
YearNum = Year(AnyDate) - 1
Case Else
ISOWeekNum = (AnyDate.ToOADate - ThisYearStart.ToOADate) \ 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?keyword="vbup1021"'
If IsNothing(WhichFormat) Then
Exit Function
End If
Dim nYear As Short
'UPGRADE_WARNING: Couldn't resolve default property of object WhichFormat.
Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
If WhichFormat = 2 Then
ISOWeekNum = CShort(VB6.Format(VB.Right(CStr(YearNum), 2), "00") &
VB6.Format(ISOWeekNum, "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?keyword="vbup1061"'
Dim WeekDay_Renamed As Object
Dim x As Short
Dim NewYear As Date

NewYear = DateSerial(WhichYear, 1, 1)
'UPGRADE_WARNING: Couldn't resolve default property of object
WeekDay_Renamed. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
WeekDay_Renamed = System.Date.FromOADate(NewYear.ToOADate - 2).ToOADate
Mod 7
'UPGRADE_WARNING: Couldn't resolve default property of object
WeekDay_Renamed. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
If WeekDay_Renamed < 4 Then
YearStart = System.Date.FromOADate(NewYear.ToOADate -
CDate(WeekDay_Renamed).ToOADate)
Else
YearStart = System.Date.FromOADate(NewYear.ToOADate -
CDate(WeekDay_Renamed).ToOADate + 7)
End If
End Function

"Shariq" wrote:
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

Nov 21 '05 #4
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
Nov 21 '05 #5
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:
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

Nov 21 '05 #6
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
Nov 21 '05 #7
Shariq, not sure if this is what you are wanting, but, how about something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

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

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

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" <Sh****@discussions.microsoft.com> wrote in message news:09**********************************@microsof t.com...
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:
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

Nov 21 '05 #8
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" <jjames700ReMoVeMe at earthlink dot net> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Shariq, not sure if this is what you are wanting, but, how about something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

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

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

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

Nov 21 '05 #9
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:
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

Nov 21 '05 #10
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:
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

Nov 21 '05 #11

"Shariq" <Sh****@discussions.microsoft.com> wrote in message news:7B**********************************@microsof t.com...
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.


It would be interesting to see how you finally got it working.
james
Nov 21 '05 #12
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:
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:
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

Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stub | last post: by
7 posts views Thread by Michael Lehn | last post: by
31 posts views Thread by Bjørn Augestad | last post: by
11 posts views Thread by Steve Gough | last post: by
2 posts views Thread by Alex Sedow | last post: by
3 posts views Thread by Steve Richter | last post: by
reply views Thread by Lou Evart | last post: by
21 posts views Thread by REH | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.