This documentation is archived and is not being maintained.

LoadResStrings method may need to be replaced

Visual Studio .NET 2003

In Visual Basic 6.0, applications created with the VB Application Wizard could optionally store string resources in an external resource file. If the Would you like to use a Resource file for the strings in your application? option was selected, a function named LoadResStrings was created in the .bas module for the project. This function used the Visual Basic 6.0 LoadResString function to extract string resources at run time.

In Visual Basic .NET, resources are handled differently than they were in Visual Basic 6.0. The Visual Basic Compatibility library contains a VB6.LoadResString function to duplicate Visual Basic 6.0 functionality.

During upgrade, if the LoadResStrings function is detected, the code within the function is not upgraded. This is because if the code generated by the wizard was subsequently modified, the upgrade tool cannot determine the correct replacement code. You will need to manually modify the code within this function in order to correctly load the string resources in Visual Basic .NET.

What to do next

  • If the code generated by the VB Application Wizard was not modified, you can perform a cut-and-paste operation on the following code and place it into your Visual Basic .NET application to replace the LoadResStrings function:
    ' Visual Basic .NET
    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 System.Drawing.Font
       Dim sCtlType As String
       Dim nVal As Short
    
       ' Set the form's caption.
       frm.Text = VB6.LoadResString(CShort(frm.Tag))
    
       ' Set the font.
       Dim FontName As String, FontSize As Double
       FontName = VB6.LoadResString(20)
       FontSize = CShort(VB6.LoadResString(21))
       frm.Font = New System.Drawing.Font(FontName, FontSize)
    
       ' 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
          ctl.Font = fnt
          sCtlType = TypeName(ctl)
          If sCtlType = "Label" Then
             ctl.Text = VB6.LoadResString(CShort(ctl.Tag))
          ElseIf sCtlType = "AxTabStrip" Then
             For Each obj In CObj(ctl).Tabs
                obj.Caption = VB6.LoadResString(CShort(obj.Tag))
                obj.ToolTipText = VB6.LoadResString(CShort(obj.ToolTipText))
             Next obj
          ElseIf sCtlType = "AxToolbar" Then
             For Each obj In CObj(ctl).Buttons
                obj.ToolTipText = VB6.LoadResString(CShort(obj.ToolTipText))
             Next obj
          ElseIf sCtlType = "AxListView" Then
             For Each obj In CObj(ctl).ColumnHeaders
                obj.Text = VB6.LoadResString(CShort(obj.Tag))
             Next obj
          Else
             nVal = 0
             nVal = Val(ctl.Tag)
             If nVal > 0 Then ctl.Text = VB6.LoadResString(nVal)
             nVal = 0
             nVal = Val(CObj(frm).ToolTip1.GetToolTip(ctl))
             If nVal > 0 Then
                CObj(frm).ToolTip1.SetToolTip(ctl, VB6.LoadResString(nVal))
             End If
          End If
       Next ctl
    
       Dim mnu As System.Windows.Forms.MainMenu = CObj(frm).MainMenu1
       If Not mnu Is Nothing Then
          LoadMenuResStrings(mnu)
       End If
    End Sub
    
    Public Sub LoadMenuResStrings(ByVal mnu As System.Windows.Forms.Menu)
       Dim mnuItem As System.Windows.Forms.MenuItem
       For Each mnuItem In mnu.MenuItems
          On Error Resume Next
          mnuItem.Text = VB6.LoadResString(CInt(mnuItem.Text))
          On Error Goto 0
          If mnuItem.MenuItems.Count > 0 Then
             LoadMenuResStrings(mnuItem)
          End If
       Next
    End Sub
    
  • If the code generated by the VB Application Wizard was modified, modify the above code to accommodate the changes, then perform a cut-and-paste operation on the code and place it into your Visual Basic .NET application to replace the LoadResStrings function. You can use the functions in the above code as an example of how to modify your own code.

See Also

Visual Basic 6.0 Compatibility Library

Show: