sandsdad

I am fairly new to C#. I need to convert some VBA code to C#. I am not real sure how to do this. I am using VS 2003. Here is a clip of the VBA code.

Dim mytpo As Object
Dim LbGroup As String
icell = 1
'
' Create a object and set the connection info in it
Set mytpo = CreateObject("CCSOLE.TPO")
mytpo.protocol = "TCP/IP"

mytpo.Server = "db1p"

mytpo.Userid = "test"

mytpo.password = "test"

' Make a connection to server
mytpo.connect
'
' Check if the connection was ok
If mytpo.ErrorCode < 0 Then
MsgBox mytpo.ErrorMsg
End
End If

Thanks



Re: Visual C# General Implementing OLE

Aaron MCP

Hi sandsdad,

The following steps might help get you started:

  1. Reference your COM library by right-clicking References in your solution explorer and selecting "Add References". Then select the "COM" tab and search through the list for your COM library.
  2. Once found, click select to add it to your selected components list, or click browse and browse to the COM library, and finally click OK.
  3. You now should be able to create a new instance of the object you need from this library in C#. The below code is an example of what you might want to do:

public class Class1 {

static int Main(string[] args) {

CCSOLE.TPO mytpo = new CCSOLE.TPO();

mytpo.protocol = "TCP/IP";
mytpo.Server = "db1p";
mytpo.Userid = "test";
mytpo.password = "test";
// Make a connection to server
mytpo.connect();
// Check if the connection was ok
if (mytpo.ErrorCode < 0) {

MessageBox.Show(mytpo.ErrorMsg);

}
return 0;

}

}

Hope this helps!






Re: Visual C# General Implementing OLE

sandsdad

Hi Aaron,

This is pretty close. I had to modify this a little, but it still wont compile. Here is where I am at.

CCSOLE.TPO mytpo = new CCSOLE.TPO();

I tried mytpo.Protocol = "TCP/IP"; but get an error "Property, indexer, or event Protocol is not supported by the language

So I tried mytpo.set_Protocol("TCP/IP");

Now I get an error "Argument 1: cannot convert from 'string' to 'ref string'

Any suggestions

Thanks again





Re: Visual C# General Implementing OLE

Aaron MCP

Hi sandsdad,

Since the property requires a referenced string, just store your values in a string and pass in the reference, for example:

string protocol = "TCP/IP";
mytpo.set_Protocol(ref protocol);

Hope this helps!

-Aaron