VB6到VB.Net转换 [英] VB6 to VB.Net Conversion

查看:85
本文介绍了VB6到VB.Net转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我转换以下vb6代码行到

vb.net。消息框应显示1/3/2005。如果今天执行。


Private Sub Form_Load()

Dim nWeekNumber As Integer

Dim ThisYearStart As Date

ThisYearStart = YearStart(今天,2)

msgbox ThisYearStart

End Sub


功能YearStart(WhichYear As整数)作为日期

Dim WeekDay作为整数

Dim NewYear作为日期

NewYear = DateSerial(WhichYear,1,1)

WeekDay =(NewYear - 2)Mod 7

如果是WeekDay< 4然后

YearStart = NewYear - WeekDay

Else

YearStart = NewYear - WeekDay + 7

结束如果

结束函数

解决方案

为什么不使用Visual Studio .NET的升级向导?

您可以使用它将VB6转换为VB.NET项目。

只需将您的代码放入VB6项目中,保存并按照升级向导的步骤进行操作。 />
of Visual Studio .NET。


祝你好运,

Lior。

" Shariq" <嘘**** @ discussions.microsoft.com>在留言中写道

新闻:E4 ********************************** @ microsof t.com ...

有人可以帮我转换以下vb6代码行到
vb.net。消息框应显示1/3/2005。如果它今天执行。

Private Sub Form_Load()
Dim nWeekNumber As Integer
Dim ThisYearStart as Date
ThisYearStart = YearStart(Today,2) msgbox ThisYearStart
End Sub

功能YearStart(WhichYear as Integer)as Date
Dim WeekDay As Integer
Dim NewYear As Date
NewYear = DateSerial(其中年,1,1)
WeekDay =(NewYear - 2)Mod 7
如果是WeekDay< 4然后
YearStart = NewYear - WeekDay
其他
YearStart = NewYear - WeekDay + 7
结束如果
结束功能


Shariq,


除了Lior,


当你使用VB2003时你可以打开工具 - >升级VB6代码粘贴它,

并且代码将在当前类中更改。


但是,我认为你不应该使用此代码。你想翻译

日期现在(15-1-2005)到2005年1月3日,什么日期是1/3/2005。在美国和

英语加拿大这意味着2005年1月3日,在大多数其他国家,它意味着1

2005年3月。


因此,请首先告诉我们您对该日期的意思。


Cor


以下VB.Net代码已从VB6但是我无法解决执行代码时产生的错误

。它假设在给定日期生成ISO Week

和年份编号; VB6代码工作正常。


Private Sub Form1_Load(ByVal eventSender As System.Object,ByVal eventArgs

As System.EventArgs)处理MyBase.Load

Dim sNewWeek As Object

Dim sNewYear As String


sDBPath =" C:\ STIApps \STLabels\TIC \ Data \__Data.mdb,0"

Text1.Text = CStr(今天)

''UPGRADE_WARNING:无法解析对象sNewWeek的默认属性。 />
点击更多:

''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)处理cmdExit.Click

结束

End Sub


Private Sub Command1_Click(ByVal eventSender As System.Object,ByVal

eventArgs As System。 EventArgs)处理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


公共职能ISOWeekNum( ByRef AnyDate As Date,可选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.ToOADat e)\ 7 + 1

YearNum =年份(AnyDate)+ 1

案例是< ThisYearStart

ISOWeekNum =(AnyDate.ToOADate - PreviousYearStart.ToOADate)\ 7 + 1

YearNum =年(AnyDate) - 1

案例否则

ISOWeekNum =(AnyDate.ToOADate - ThisYearStart.ToOADate)\ 7 + 1

YearNum =年(AnyDate)

结束选择


''UPGRADE_NOTE:IsMissing()已更改为IsNothing()。点击查看更多信息:

''ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword =" vbup1021"''

如果IsNothing(WhichFormat)那么

退出功能

结束如果

昏暗的那么短暂

''升级_警告:无法解析对象WhichFormat的默认属性。

点击更多:

''ms-help://MS.VSCC.2003/commoner/redir/redirect .htm?keyword =" vbup1037"''

如果WhichFormat = 2那么

ISOWeekNum = CShort(VB6.Format(VB.Right(CStr(YearNum),2 )," 00"&

VB6.Format(ISOWeekNum," 00"))

结束如果

结束功能

函数YearStart(ByRef WhichYear As Short)As Date

''UPGRADE_NOTE:WeekDay已升级为WeekDay_Renamed。点击查看更多信息:

''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:无法解析对象的默认属性

WeekDay_Renamed。点击查看更多信息:

''ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword =" vbup1037"''

WeekDay_Renamed = System.Date.FromOADate(NewYear.ToOADate - 2)。ToOADate

Mod 7

''UPGRADE_WARNING:无法解析对象的默认属性

WeekDay_Renamed。点击查看更多信息:

''ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword =" vbup1037"''

如果WeekDay_Renamed< 4然后

YearStart = System.Date.FromOADate(NewYear.ToOADate -

CDate(WeekDay_Renamed).ToOADate)

Else

YearStart = System.Date.FromOADate(NewYear.ToOADate -

CDate(WeekDay_Renamed).ToOADate + 7)

结束如果

结束功能


" Shariq"写道:

有人可以帮我转换下面的vb6代码行到
vb.net。消息框应显示1/3/2005。如果它今天执行。

Private Sub Form_Load()
Dim nWeekNumber As Integer
Dim ThisYearStart as Date
ThisYearStart = YearStart(Today,2) msgbox ThisYearStart
End Sub

功能YearStart(WhichYear as Integer)as Date
Dim WeekDay As Integer
Dim NewYear As Date
NewYear = DateSerial(其中年,1,1)
WeekDay =(NewYear - 2)Mod 7
如果是WeekDay< 4然后
YearStart = NewYear - WeekDay
其他
YearStart = NewYear - WeekDay + 7
结束如果
结束功能


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



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



这篇关于VB6到VB.Net转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆