Home » VB.NetRSS

How to upgrade VB6 application into VS 2008 application?

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

 

8 Answers Found

 
 

Answer 2

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.

 

Answer 3

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

 

 

Answer 4

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?

 

Answer 5

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)
 

Answer 6

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 )

OptionStrictOff

OptionExplicitOn

FriendClass frmMain

      Inherits System.Windows.Forms.Form

     

      PrivateSub frmMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) HandlesMyBase.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"'

            IfApp.PrevInstance = TrueThen

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

                  End

            EndIf

           

            numSampsPerChannel = 1000

            Call ReadValue()

            Call ChkCheck()

            Call USBCheck()

           

      EndSub

 

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 )

OptionStrictOff

OptionExplicitOn

Module ModIni

     

      'declares for ini controlling

      PublicDeclareFunction timeGetTime Lib"Winmm.dll" () AsInteger

      PrivateDeclareFunction GetPrivateProfileSection Lib"kernel32"  Alias"GetPrivateProfileSectionA"(ByVal lpAppName AsString, ByVal lpReturnedString As String, ByVal nSize AsInteger, ByVal lpFileName AsString) AsInteger

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

      PrivateDeclareFunction GetPrivateProfileString Lib"kernel32"  Alias"GetPrivateProfileStringA"(ByVal lpApplicationName AsString, ByVal lpKeyName As Any, ByVal lpDefault AsString, ByVal lpReturnedString AsString, ByVal nSize AsInteger, ByVal lpFileName AsString) As Integer

      PrivateDeclareFunction WritePrivateProfileSection Lib"kernel32"  Alias"WritePrivateProfileSectionA"(ByVal lpAppName AsString, ByVal lpString As String, ByVal lpFileName AsString) AsInteger

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

      PrivateDeclareFunction WritePrivateProfileString Lib"kernel32"  Alias"WritePrivateProfileStringA"(ByVal lpApplicationName AsString, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName AsString) AsInteger

      PrivateDeclareFunction GetWindowsDirectory Lib"kernel32"  Alias"GetWindowsDirectoryA"(ByVal lpBuffer AsString, ByVal nSize AsInteger) AsInteger

      PrivateDeclareFunction GetPrivateProfileSectionNames Lib"kernel32.dll"  Alias"GetPrivateProfileSectionNamesA"(ByVal lpszReturnBuffer AsString, ByVal nSize AsInteger, ByVal lpFileName AsString) As Integer

      'reads ini string

      PublicFunction ReadINI(ByRef filename AsString, ByRef Section As String, ByRef Key AsString) AsString

            Dim RetVal AsNew VB6.FixedLengthString(255)

            Dim v As Integer

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

            ReadINI = Left(RetVal.Value, v)

      EndFunction

     

      'writes ini

      PublicSub WriteINI(ByRef filename AsString, ByRef Section As String, ByRef Key AsString, ByRef Value AsString)

            WritePrivateProfileString(Section, Key, Value, filename)

      EndSub

     

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

            Dim sFile AsString

           

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

            GetSettingsINI = ReadINI(sFile, whichSection, whichSetting)

      EndFunction

     

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

            Dim sFile AsString

           

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

            WriteINI(sFile, whichSection, whichSetting, Value)

      EndFunction

EndModule

 

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 )

OptionStrictOff

OptionExplicitOn

FriendClass frmPreset

      Inherits System.Windows.Forms.Form

     

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

           

            Dim sFile AsString

            Dim tempfile AsString

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

            WithdlgCommonDialog

                  .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

                        ExitSub

                  EndIf

                  If .FileName <> "Log Folder Location"Then

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

                  EndIf

            EndWith

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

           

      EndSub

 

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 )

OptionStrictOff

OptionExplicitOn

Module ModUSBCheck

     

      PublicFunction USBCheck() AsObject

           

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

            Call getAnalog1()

           

      EndFunction

EndModule

 

 

Answer 7

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"

 

Answer 8

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?

 

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter