VB6 to VB.NET conversion error
-
Wednesday, June 27, 2007 2:56 PM
Hello,
While trying to convert a program (which builds and runs correctly
in VB6.0) to VB.NET, I had 102 errors. I have managed to get that number down to 14 errors. I believe 10-12 of those errors left have to do with the following:
Code Snippet'VB 6.0 ORIGINAL CODE
Sub LoadResStrings(frm As Form)
On Error Resume Next
Dim ctl As Control
Dim obj As Object
Dim fnt As Object
Dim sCtlType As String
Dim nVal As Integer
'set the form's caption
frm.Caption = LoadResString(CInt(frm.Tag))
'set the font
Set fnt = frm.Font
fnt.Name = LoadResString(20)
fnt.Size = CInt(LoadResString(21))
'set the controls' captions using the caption
'property for menu items and the Tag property
'for all other controls
For Each ctl In frm.Controls
Set ctl.Font = fnt
sCtlType = TypeName(ctl)
If sCtlType = "Label" Then
ctl.Caption = LoadResString(CInt(ctl.Tag))
ElseIf sCtlType = "Menu" Then
ctl.Caption = LoadResString(CInt(ctl.Caption))
ElseIf sCtlType = "TabStrip" Then
For Each obj In ctl.Tabs
obj.Caption = LoadResString(CInt(obj.Tag))
obj.ToolTipText = LoadResString(CInt(obj.ToolTipText))
Next
ElseIf sCtlType = "Toolbar" Then
For Each obj In ctl.Buttons
obj.ToolTipText = LoadResString(CInt(obj.ToolTipText))
Next
ElseIf sCtlType = "ListView" Then
For Each obj In ctl.ColumnHeaders
obj.Text = LoadResString(CInt(obj.Tag))
Next
Else
nVal = 0
nVal = Val(ctl.Tag)
If nVal > 0 Then ctl.Caption = LoadResString(nVal)
nVal = 0
nVal = Val(ctl.ToolTipText)
If nVal > 0 Then ctl.ToolTipText = LoadResString(nVal)
End If
Next
End SubAnd this is what it generated:
Code SnippetVB .NET CONVERTED CODE
Sub
LoadResStrings(ByRef frm As System.Windows.Forms.Form) On Error Resume Next Dim ctl As System.Windows.Forms.Control Dim obj As Object Dim fnt As Object Dim sCtlType As String Dim nVal As Short 'set the form's captionfrm.Text =
My.Resources.ResourceManager.GetString("str" + CStr(CShort(frm.Tag))) My.Computer. 'set the fontfnt = frm.Font
'UPGRADE_WARNING: Couldn't resolve default property of object fnt.Name. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'fnt.Name =
My.Resources.str20 'UPGRADE_WARNING: Couldn't resolve default property of object fnt.Size. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'fnt.Size =
CShort(My.Resources.str21) 'set the controls' captions using the caption 'property for menu items and the Tag property 'for all other controls For Each ctl In frm.Controlsctl.Font = fnt
'UPGRADE_WARNING: TypeName has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'sCtlType = TypeName(ctl)
If sCtlType = "Label" Thenctl.Text =
My.Resources.ResourceManager.GetString("str" + CStr(CShort(ctl.Tag))) ElseIf sCtlType = "Menu" Thenctl.Text =
My.Resources.ResourceManager.GetString("str" + CStr(CShort(ctl.Text))) ElseIf sCtlType = "TabStrip" Then 'UPGRADE_WARNING: Couldn't resolve default property of object ctl.Tabs. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' For Each obj In ctl.Tabs 'UPGRADE_WARNING: Couldn't resolve default property of object obj.Caption. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' 'UPGRADE_WARNING: Couldn't resolve default property of object obj.Tag. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'obj.Caption =
My.Resources.ResourceManager.GetString("str" + CStr(CShort(obj.Tag))) 'UPGRADE_ISSUE: Object property obj.ToolTipText was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"' 'UPGRADE_WARNING: Couldn't resolve default property of object obj.ToolTipText. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'obj.ToolTipText =
My.Resources.ResourceManager.GetString("str" + CStr(CShort(obj.ToolTipText))) Next obj ElseIf sCtlType = "Toolbar" Then 'UPGRADE_WARNING: Couldn't resolve default property of object ctl.Buttons. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' For Each obj In ctl.Buttons 'UPGRADE_ISSUE: Object property obj.ToolTipText was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"' 'UPGRADE_WARNING: Couldn't resolve default property of object obj.ToolTipText. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'obj.ToolTipText =
My.Resources.ResourceManager.GetString("str" + CStr(CShort(obj.ToolTipText))) Next obj ElseIf sCtlType = "ListView" Then 'UPGRADE_WARNING: Couldn't resolve default property of object ctl.ColumnHeaders. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' For Each obj In ctl.ColumnHeaders 'UPGRADE_WARNING: Couldn't resolve default property of object obj.Text. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' 'UPGRADE_WARNING: Couldn't resolve default property of object obj.Tag. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'obj.Text =
My.Resources.ResourceManager.GetString("str" + CStr(CShort(obj.Tag))) Next obj ElsenVal = 0
nVal = Val(ctl.Tag)
If nVal > 0 Then ctl.Text = My.Resources.ResourceManager.GetString("str" + CStr(nVal))nVal = 0
'UPGRADE_ISSUE: Control property ctl.ToolTipText was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'nVal = Val(ctl.ToolTipText)
'UPGRADE_ISSUE: Control property ctl.ToolTipText was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"' If nVal > 0 Then ctl.ToolTipText = My.Resources.ResourceManager.GetString("str" + CStr(nVal)) End If Next ctl End SubThe errors I am getting have to do with every place it says
"My.Resources.RecourceManager..."
The error says something about "Resources" not being a member of "My."
This project is used for intermingling with Excel.
Thank you in advance for your help.
Tim
All Replies
-
Wednesday, June 27, 2007 5:44 PMModerator
Moved from VB Language to Upgrade forum.
Also, please see the post http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=478161&SiteID=1 for more VB6 resources.
-
Friday, June 29, 2007 4:11 AM
Timothy Atchley,
According to your upgrade problem on My.Resources namespace, I would like to recommend you to take a look at the source code of My.Resources as follows:
Code Snippet'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50326.0
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
<Assembly: Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope:="member", Target:="My.Resources.Resources.get_ResourceManager():System.Resources.ResourceManager"), _
Assembly: Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope:="member", Target:="My.Resources.Resources.get_Culture():System.Globalization.CultureInfo"), _
Assembly: Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope:="member", Target:="My.Resources.Resources.set_Culture(System.Globalization.CultureInfo):Void")>
Namespace My.Resources
'This class was auto-generated by the StronglyTypedResourceBuilder
'class via a tool like ResGen or Visual Studio.
'To add or remove a member, edit your .ResX file then rerun ResGen
'with the /str option, or rebuild your VS project.
'''<summary>
''' A strongly-typed resource class, for looking up localized strings, etc.
'''</summary>
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Returns the cached ResourceManager instance used by this class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If (resourceMan Is Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("DataCachingVB.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
'''<summary>
''' Overrides the current thread's CurrentUICulture property for all
''' resource lookups using this strongly typed resource class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend Property Culture() As Global.System.Globalization.CultureInfo
Get
Return resourceCulture
End Get
Set(ByVal value As Global.System.Globalization.CultureInfo)
resourceCulture = value
End Set
End Property
Friend ReadOnly Property NWLogo_Small() As System.Drawing.Bitmap
Get
Return CType(ResourceManager.GetObject("NWLogo_Small", resourceCulture), System.Drawing.Bitmap)
End Get
End Property
End Module
End Namespace
You can also take a look at My.Resources Object that provides properties and classes for accessing the application's resources in MSDN, then make a comparison to your upgraded VB.NET code:
http://msdn2.microsoft.com/en-us/library/6wkcc526(VS.80).aspx
I hope you are able to upgrade the VB6 code to VB.NET successfully. Thanks again for your question.
-
Friday, June 29, 2007 5:09 PMModerator
Hi Tim,
I'm not clear if you're getting compiler or runtime errrors but if you open the resources by opened My Project in the Solution Explorer and going to the Resource Tab are the strings you're looking for there? Are they names STR# where # is the original index? This is what the upgraded code is looking for with the lines like; GetString("str" + CStr(CShort(obj.Tag))).
If that looks ok then if you could provide a little bit more specific information that would make easier to help.
Having said that, I expect you're getting compile errors because most controls no longer have a tooltiptext property and this line like this are no longer compiling
ResourceManager.GetString("str" + CStr(CShort(obj.ToolTipText))).
As this Upgrade Issue describes: 'UPGRADE_ISSUE: Control property ctl.ToolTipText was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'

