Avatar of tatton777
tatton777
Flag 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.
.NET ProgrammingVisual Basic.NETC#

Avatar of undefined
Last Comment
tatton777

8/22/2022 - Mon
BuggyCoder

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

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)
BuggyCoder

pass it string.Empty as default value
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
wdosanjos

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
tatton777

ASKER
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?
tatton777

ASKER
Nevermind. I got this to work with the Activator code. THANKS!
Anuradha Goli

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

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
tatton777

ASKER
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.