locked
How to upgrade VB6 application into VS 2008 application?

    General discussion

  • Hi Friends,

    I try to upgrade VB6 application into VS 2008 application, how to i get to start?

    Example can i upload project then use the header menu " upgrade the VB code " by selecting all the code and redraw the form?

    Or can i save the project.vbp as solution or vbproj?

     

    Tks

    Saturday, June 26, 2010 8:05 AM

All replies

  • Make sure you have the MSDN help files installed on your PC.  After running the built in upgrade engine your code is going to be littered with lines like:

     

    'UPGRADE_WARNING: Form event frmErrLog.Activate has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'


    And having the MSDN files will allow you to Ctrl+Click the link for a quick assist.

    Anecdotally I've been doing a code upgrade from VB6 to VB.NET in VS2008 for the past 5 months, and it is painful work.  Some stuff is really easy like replacing LenB with Len, and some stuff requires attribute marshalling, delegate class creation, and sometimes creating custom controls (ala .SelPrint) to get the same functionality from your upgraded project.

    My best advice is to be patient, and if you have time, modify the VB6 code to make it more upgrade friendly.


    That free e-book is kinda neat to read, but doesn't really help 100%.  Not a bad way to kill a few days if your getting paid to "research" the upgrade, but otherwise mostly tells you things that will be meaningless until your looking at errors.

    Thursday, July 01, 2010 2:11 PM
  • I agree with Kevin. I too am migrating an app developed in VB6.0 to VB 2008 and possibly later on to VB 2010. Some of the work is tedious. You have to be careful when declaring integer variables to determine whether you can use the Integer type from VB6 or if you need to modify the declaration to use a variable equivalent to the VB6.0 Integer type. This applies to other types too. Kevin is right when he says it is a matter of patience. Regards, Saga

     

    Friday, July 02, 2010 6:38 PM
  • Hi Paul & Kevin & Saga,

    First of all thank you for your advise and recommend web link.

    I also encounter some 'UPGRADE_WARNING: Form event frmErrLog.Activate has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'

    Currently i have managed to convert the Vb6 project in VS2008 platform. However i have 29 error and 1 warning.

    I believe Most of the error i faced are the syntax different used and declaration in vb6, which i need to modify them using VS2008.

    Perhap i will appreciate you guys recomend more useful link or even video link for the syntax different upgrading from VB6 to VS208 and declaration comment/function?

    Saturday, July 24, 2010 10:55 AM
  • The following links might help. If you have specific conversion problems I would post them here so that we can try to resolve the issues.

    Language Changes for Visual Basic 6.0 Users

    http://www.thescarms.com/vbasic/vb6vsvbnet.aspx

     


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Saturday, July 24, 2010 11:58 AM
  • Hi Paul,

    Appreciate your kind suggestion.

    Ok, i try to hightlight the common error ( 5 example ) and warning ( 2 example ) as # numbering

    Error #01 > Name 'App' is not declared. ( line 9 )

    Option Strict Off

    Option Explicit On

    Friend Class frmMain

          Inherits System.Windows.Forms.Form

         

          Private Sub frmMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load 'Initial Load

               

                'UPGRADE_ISSUE: App property App.PrevInstance was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="076C26E5-B7A9-4E77-B69C-B4448DF39E58"'

                If App.PrevInstance = True Then

                      MsgBox("Application Already Running!" & vbCrLf & "Please End Previous Program.", MsgBoxStyle.Information, "Application Load Error")

                      End

                End If

               

                numSampsPerChannel = 1000

                Call ReadValue()

                Call ChkCheck()

                Call USBCheck()

               

          End Sub

     

    Error #02 > ‘As Any’ is not supported in ‘Declare’ statements ( line 9, 13 )

    Warning #01 > Function ‘SaveSettingsINI’ doesn’t return a value on all code paths. A null reference exception could occur at run time when the result is used. ( line 42 )

    Option Strict Off

    Option Explicit On

    Module ModIni

         

          'declares for ini controlling

          Public Declare Function timeGetTime Lib "Winmm.dll" () As Integer

          Private Declare Function GetPrivateProfileSection Lib "kernel32"  Alias "GetPrivateProfileSectionA"(ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer

          'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'

          Private Declare Function GetPrivateProfileString Lib "kernel32"  Alias "GetPrivateProfileStringA"(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer

          Private Declare Function WritePrivateProfileSection Lib "kernel32"  Alias "WritePrivateProfileSectionA"(ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer

          'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'

          'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'

          Private Declare Function WritePrivateProfileString Lib "kernel32"  Alias "WritePrivateProfileStringA"(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Integer

          Private Declare Function GetWindowsDirectory Lib "kernel32"  Alias "GetWindowsDirectoryA"(ByVal lpBuffer As String, ByVal nSize As Integer) As Integer

          Private Declare Function GetPrivateProfileSectionNames Lib "kernel32.dll"  Alias "GetPrivateProfileSectionNamesA"(ByVal lpszReturnBuffer As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer

          'reads ini string

          Public Function ReadINI(ByRef filename As String, ByRef Section As String, ByRef Key As String) As String

                Dim RetVal As New VB6.FixedLengthString(255)

                Dim v As Integer

                v = GetPrivateProfileString(Section, Key, "", RetVal.Value, 255, filename)

                ReadINI = Left(RetVal.Value, v)

          End Function

         

          'writes ini

          Public Sub WriteINI(ByRef filename As String, ByRef Section As String, ByRef Key As String, ByRef Value As String)

                WritePrivateProfileString(Section, Key, Value, filename)

          End Sub

         

          Function GetSettingsINI(ByRef whichSetting As String, ByRef whichSection As String) As String

                Dim sFile As String

               

                sFile = My.Application.Info.DirectoryPath & "\Tool.ini"

                GetSettingsINI = ReadINI(sFile, whichSection, whichSetting)

          End Function

         

          Function SaveSettingsINI(ByRef whichSetting As String, ByRef Value As String, ByRef whichSection As String) As Object

                Dim sFile As String

               

                sFile = My.Application.Info.DirectoryPath & "\Tool.ini"

                WriteINI(sFile, whichSection, whichSetting, Value)

          End Function

    End Module

     

    Error #03 > ‘DAQmx’ is not a member of ‘NIDAQmxCAPI’ ( line 6 )

                'create the daqmx tast

                'UPGRADE_ISSUE: COM expression not supported: Module methods of COM objects. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="5D48BAC6-2CD4-45AD-B1CC-8E4A241CDB58"'

                DAQmxErrChk(NIDAQmxCAPI.DAQmx.DAQmxCreateTask("", taskHandle))

                taskIsRunning = True

     

    Error #04 > ‘code’ is not a member of ‘string’ ( line 6 )

                      'trim it to the actual length and display the message

                      errorString = Left(errorString, InStr(errorString, Chr(0)))

                      'UPGRADE_WARNING: Couldn't resolve default property of object Error.code. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'

                      Err.Raise(ErrorToString().code,  , errorString)

     

    Error #05 > Name ‘dlgCommonDialog’ is not declared. ( line 11 )

    Option Strict Off

    Option Explicit On

    Friend Class frmPreset

          Inherits System.Windows.Forms.Form

         

          Private Sub cmdOpenDir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOpenDir.Click 'Open directory button pressed

               

                Dim sFile As String

                Dim tempfile As String

                'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'

                With dlgCommonDialog

                      .Title = "Save As"

                      .FileName = "Log Folder Location"

                      'UPGRADE_WARNING: The CommonDialog CancelError property is not supported in Visual Basic .NET. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8B377936-3DF7-4745-AA26-DD00FA5B9BE1"'

                      .CancelError = False

                      .InitialDirectory = PathToSave 'App.Path

                      'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'

                      .Filter = "Data Files (*.csv)|*.csv"

                      'UPGRADE_WARNING: MSComDlg.CommonDialog property dlgCommonDialog.Flags was upgraded to dlgCommonDialogSave.OverwritePrompt which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'

                      .OverwritePrompt = True

                      .ShowDialog()

                      If Len(.FileName) = 0 Then

                            Exit Sub

                      End If

                      If .FileName <> "Log Folder Location" Then

                            txtDir.Text = Mid(.FileName, 1, InStrRev(.FileName, "\") - 1)

                      End If

                End With

                Call SaveSettingsINI("PathToSave", (txtDir.Text), "Tool")

               

          End Sub

     

    Warning #02 > Function ‘USBCheck’ doesn’t return a value on all code paths. A null reference exception could occur at run time when the result is used. ( line 7 )

    Option Strict Off

    Option Explicit On

    Module ModUSBCheck

         

          Public Function USBCheck() As Object

               

                frmMain.lblStatus.Text = "USB Communication OK. Ready for Measurement."

                Call getAnalog1()

               

          End Function

    End Module

     

    Sunday, July 25, 2010 7:51 AM
  • To fix a couple of your errors, the "As Any" type is not supported.  You need to specify what that would be.  I ran into this quite a bit.  Just look through your code and see where that is being called and change as appropriate.  If you have multiple data types being used there, make copies and change that data type, its all good.

     

    The dlgCommonDialog error can be resolved by using the .NET equivalents.  There is a SaveFileDialog, OpenFileDialog, and .... another I cant remember right now.  The upgrade warnings related to the dlgCommonDialog can be resolved by looking at what properties are supported by the new .NET functions.

     

    Errors 3 and 4 I can't do anything with, don't have the rest of the picture.

     

    Warning 2 is coming up because you have an uninitialized variable.  Things don't Dim into having a value, they default to NULL.  You might return a NULL and break something.  Set it to 0, "", or something similar to make that go away, or if you know what you are doing and have tested it like crazy, ignore it.  Bad practice, but it works.

     

    Example:

    "WritePrivateProfileStringA"(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
    
    "WritePrivateProfileStringA"(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Byte, ByVal lpFileName As String) As Integer
    
    "WritePrivateProfileStringA"(ByVal lpApplicationName As String, ByVal lpKeyName As Short, ByVal lpString As String, ByVal lpFileName As String) As Integer
    Multiple definition for the same thing, just gotta make sure that your data types are good for replacing the "As Any"

    • Edited by KevinMarsalla Monday, July 26, 2010 4:48 PM Example added
    Monday, July 26, 2010 4:46 PM
  • Hi Kevin,

    Good day to you, I manage to reduce 29 error to 26 error after using your suggestion :

    Error #02, replace from "Any" to "String"

    "WritePrivateProfileStringA"(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer

    Error #05, dlgCommonDialog is an API VB6 function ( under Project > Components > Controls > ) i enable 2 x function as below :

    Microsoft Comm Control 6.0 & Microsoft Common Dialog Control 6.0

    May I know how do i use the .NET equivalents such as SaveFileDialog, OpenFileDialog, and ....etc?

    Or do we need to add Reference at VS2008?

     

    Wednesday, September 01, 2010 3:59 PM