473,708 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 21 '05 #1
12 4519
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****@discuss ions.microsoft. com> wrote in message
news:E4******** *************** ***********@mic rosoft.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(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

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(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:
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

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(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

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(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" <Sh****@discuss ions.microsoft. com> wrote in message news:09******** *************** ***********@mic rosoft.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(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

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" <jjames700ReMoV eMe at earthlink dot net> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
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

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5651
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases at the bottom. Hope you can help me understand the "explicit" keyword and its usage. Specifically, Is "explicit" keyword only associated with constructor in C++? What's "implied conversion of types"?
7
3257
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But I couldn't find the exact rule in the C++ standard. And what if the classes have template parameters? It would be great if somebody could get me a rough hint where in the
16
5131
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. And K&R2 mentions "signed extension" everywhere. Reading some old clc posts, I've beginning to realize that these books are over-generalizing the topic. I am just wondering what the difference between the following pairs of terms are: 1)...
31
6635
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one variable becomes 364 and the other one becomes 365. Does anyone have any insight to what the problem is? Thanks in advance. Bjørn
11
7613
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type Test. I expected the same error from the following line, but it compiles fine. The double is silently truncated to an int and then fed in to the implicit conversion operator. Why does this happen? Is there any way that I can keep the implicit...
2
6867
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public static explicit System.IntPtr (long);
3
4452
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while calling the constructor 'MyString::MyString(const wchar_t *)' c:\SrNet\jury\JuryTest.h(21) : see declaration of 'MyString::MyString' The class "StringData" uses a, whatever you call it, operator const
0
2292
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million pages to a variety of formats. SII's service bureau has a reputation as being a least-cost provider that can offer a timely turnaround with 100% accuracy. Here are some of the formats SII has converted over the last 20 years:
0
1864
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also provides form data entry, data capture, HTML/SGML coding, image scanning, file conversion with low cost, high quality,99.98% accuracy and time bound. Data Conversion Services offer cost effective data conversion projects, Outsourcing Data...
21
2452
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the type is not a single identifier or keyword. Which one is correct? For example: unsigned long x = unsigned long(y); REH
0
8788
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9290
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9159
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4713
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.