Link to home
Start Free TrialLog in
Avatar of tatton777
tatton777Flag for United States of America

asked on

Need this visual basic code converted to C#

Hello,
My credit card processor provided a VB DLL for me to use in sending data to and receiving data from them. My website is in C# so I need to figure out how to incorporate this DLL into it.

In the example from the credit card processor I am to add a reference to SendPmt.dll within the VB project and then use this code

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Initialize string
        Dim strData As String
        Dim strReturn As String

        Dim objSendPmt As SendPmt.clsSendPmt
        objSendPmt = CreateObject("SendPmt.clsSendPmt")

        strData = Replace(txtInput.Text, vbCrLf, Chr(10))

        strReturn = objSendPmt.SendPayment(strData, "test")

    End Sub

Open in new window


So far in my C# attempt I have added a reference to the SendPmt.dll from the processor and a reference to Microsoft.VisualBasic.dll. I think I am on the right track using the Microsoft.VisualBasic.dll but I can't seem to get it to work.
Avatar of BuggyCoder
BuggyCoder
Flag of India image

converter.telerik.com

protected void  Button1_Click(object sender, System.EventArgs e)
{
	// Initialize string
	string strData = null;
	string strReturn = null;

	SendPmt.clsSendPmt objSendPmt = default(SendPmt.clsSendPmt);
	objSendPmt = Interaction.CreateObject("SendPmt.clsSendPmt");

	strData = Strings.Replace(txtInput.Text, Constants.vbCrLf, Strings.Chr(10));

	strReturn = objSendPmt.SendPayment(strData, "test");

}

Open in new window

Avatar of tatton777

ASKER

I get a No overload for method 'CreateObject' takes '1' argument

Even though the VB example works with one parameters, CreateObject is defined as taking two.

CreateObject(string ProgId, string ServerName)
pass it string.Empty as default value
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I got both of these examples to work. However, they both return the same error.

"ERR: Unable to send data to remote host 26021"

I am assuming this is coming from within the SendPmt.dll.

I just verified that the VB code worked and it does. Why would C# throw this curve ball?
Nevermind. I got this to work with the Activator code. THANKS!
protected void  // ERROR: Handles clauses are not supported in C#
Button1_Click(object sender, System.EventArgs e)
{
	// Initialize string
	string strData = null;
	string strReturn = null;

	SendPmt.clsSendPmt objSendPmt = default(SendPmt.clsSendPmt);
	objSendPmt = Interaction.CreateObject("SendPmt.clsSendPmt");

	strData = Strings.Replace(txtInput.Text, Constants.vbCrLf, Strings.Chr(10));

	strReturn = objSendPmt.SendPayment(strData, "test");

}

//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik, @toddanglin
//Facebook: facebook.com/telerik
//=======================================================

Open in new window

Thanks so much for this excellent code. The other code examples didn't fail to compile, however, yours is the only code that correctly instantiated the VB dll.