Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21096

how to assign objects-Employee object returned by .net assembly- Emp variable in vb6

$
0
0
Hi All

I have the following code created in C#.Net

using System;
using System.Runtime.InteropServices;

namespace TestUtility
{
[Guid("422EF1C9-AC03-4C54-BA86-34EF06B97E50")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class Employee
{
[ComVisible(true)]
public int EmployeeId { get; set; }

[ComVisible(true)]
public string EmployeeName{ get; set; }
}

[Guid("8320FE4C-08AF-4A53-8917-E5AB74A8FC55")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class TestUtilityClass
{
public TestUtilityClass() { }

[ComVisible(true)]
public string HelloWorld()
{
return "Hello World";
}

[ComVisible(true)]
public Employee GetEmployeeItem()
{
return new Employee() { EmployeeId = 1, EmployeeName = "Suren" };

}

[ComVisible(true)]
public Employee EmployeeItem
{
get
{
return new Employee() { EmployeeId = 1, EmployeeName = "Suren" };
}

}


}
}


i have added the TestUtility.tbl file reference in vb6 project.

Private Sub Command1_Click()
Dim testObj As New TestUtilityClass
Dim objEmp As Employee
Dim objEmp1 As Employee
Dim EmpId As Integer
Dim EmpName As String
objEmp = testObj.EmployeeItem --- this line of code gives error
objEmp = testObj.GetEmployeeItem() --- this line of code gives error
EmpId = testObj.EmployeeItem.EmployeeId -- this line works
EmpName = testObj.EmployeeItem.EmployeeName -- this line works
MsgBox testObj.HelloWorld()
End Sub

Could some one please explain me how to assign GetEmployeeItem() function retuned Employee object and EmployeeItem project object to the respective objEmp and objeEmp1 object created in the vb6 program.

Need to know how to fix the errors in the above vb6 code. Refer the code for inline comments

Viewing all articles
Browse latest Browse all 21096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>