Convert VB6 project to VB.Net

Joined
Jun 4, 2013
Messages
1
Programming Experience
5-10
I want to convert VB6 project to VB.Net. I an facing some problems.
I have separated huge VB6 project into separate dlls based in functionality. All business logic is in dll and UI is in exe program.
Out of all dlls, one dll only caontains UDT(User Defined Types) and it's used by Main exe program and all other dlls. Now I want to Convert all dlls and main program in VB.Net STEP BY STEP. I have decided to convert all dlls first and then main program.
If I convert other dll to .Net I ran into Case1 error
If I convert UDT dll to .Net using Structure, I got case 2 error

I am giving my dummy code for both the cases and problem/error description below.

Case 1:
UDT dll is in VB6 -->Name: Dll_EmployeeType
Type Employee_Properties
Employee_Id as integer
Employee_Name as String
Employee_Address as string
End Type
.Net Dll -->Name: Dll_Employee_Methods --> this refers vb6 dll Dll_EmployeeType
Class Cls_Employee
Function Display_NoOf_Employees(byval arr_employee as Dll_EmployeeType. Employee_Properties)
Msgbox ubound(arr_employee)
End Class
VB6 Exe: main program --> this refers vb6 dll Dll_EmployeeType and Dll_Employee_Methods
This program has form and button on it.
On Button_Click
Dim arr_employee() as Dll_EmployeeType. Employee_Properties
Redim arr_employee(1 to 2)

arr_employee(1). Employee_Id = 1
arr_employee(1). Employee_Name = ?name1?
arr_employee(1). Employee_Address = ?address1?

arr_employee(2). Employee_Id = 2
arr_employee(2). Employee_Name = ?name2?
arr_employee(2). Employee_Address = ?address2?

dim obj as new Dll_Employee_Methods. Cls_Employee
call obj. Display_NoOf_Employees(arr_employee)

error occurs at above line is ?Class does not support an automation or does not support expected interface?

Note: If .Net dll code is in normal class ? no intellicense is displayed in main program
If .Net dll code is in COM class ? intellicense is displayed in main program
But the error is same as above

Case 2:
Vb6 UDT dll is converted to .Net having structure
?Build tlb using COM checkbox as checked
?Add reference of it to Main exe program
?Run program
Throws an error ?Variable uses an automation type not supported in Visual basic? at first line(dim arr_employee() as?..)
 
Last edited:
Without some real code to look at it may not be simple to resolve. However, keep in mind that while some of the VB6 syntax is similar, much of the structure is completely different.

Try changing the "Type" to a "Structure" and create an initializer. I've had issues with structures in the past when I used them without initializers

VB.NET:
Structure Employee_Properties
    Employee_Id as Integer
    Employee_Name as String
    Employee_Address as String
End Structure

Reference the project or DLL in your executable program to get the intellisense. Make sure to set the build order priority correctly.

Don't reference the DLL directly, instead, import it into the executable and access the structure using the namespace.structure format if you are even using a namespace.

Example:
VB.NET:
Imports Dll_EmployeeType

Public Partial Class Form1

    Private Sub MyButton_Clicked(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyButton.Clicked
        'If you know how many employees you are adding at this point, simply declare its size when you dimension it
        'Also, your lower bounds should start with 0 not 1, thus for two items you use 1.
        Dim arr_employee(1) As New Employee_Properties
        arr_employee(0).Employee_Id = 1
        arr_employee(0).Employee_Name = "name1"
        arr_employee(0).Employee_Address = "address1"
        arr_employee(1).Employee_Id = 2
        arr_employee(1).Employee_Name = "name2"
        arr_employee(1).Employee_Address = "address2"
        MsgBox (arr_employees.Length.ToString)
    End Sub

End Class
 
Back
Top