Wednesday, March 21, 2012

Passing a struct to a function

Hi Folks

I'm attempting to pass a structure to a function. The structure definition in the .aspx file and the dll are indentical. The approach looks correct, but I get this error:

Value of type 'ASP.processing_aspx.transDetails' cannot be converted to 'app.Settle.transDetails'.

Is this possible or is there a better method of passing a large number of parameters to a function?

The submitting code:

<script runat="server" language="VB"
Structure authResultsStruct
Dim Approved As Integer
Dim ErrorMsg As String
End Structure

Structure transDetails
Dim ClientID As Integer
Dim CardName As String
Dim CardNumber AS String
Dim ExpDate AS String
Dim Amount AS Double
Dim Address AS String
Dim Stripe1 AS String
Dim Stripe2 AS String
Dim Invoice AS String
Dim Zip AS String
Dim BankAccount AS String
Dim RoutingNumber AS String
Dim Created AS String
Dim PaymentType AS Integer
End Structure

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim payment AS transDetails
payment.ClientID = Request.Form("ClientID")
payment.CardName = Request.Form("CardName")
payment.CardNumber = Request.Form("CardNumber")
payment.ExpDate = Request.Form("ExpDate")
payment.Amount = Request.Form("Amount")
payment.Address = "1234"
payment.Stripe1 = Request.Form("Stripe1")
payment.Stripe2 = Request.Form("Stripe2")
payment.Invoice = Request.Form("Invoice")
payment.Zip = Request.Form("Zip")
payment.BankAccount = Request.Form("BankAccount")
payment.RoutingNumber = Request.Form("RoutingNumber")
payment.Created = Request.Form("Created")
payment.PaymentType = Request.Form("PaymentType")

Dim results AS authResultsStruct
Dim auth As New Settle()
'Dim myDataGrid
results = auth.Authorize( payment ) As authResultsStruct
Console.WriteLine(results.Status)
Console.WriteLine(result.ErrMsg)
End Sub

</script
Here is the function with struct definition:

Structure transDetails
Dim ClientID As Integer
Dim CardName As String
Dim CardNumber As String
Dim ExpDate As String
Dim Amount As Double
Dim Address As String
Dim Stripe1 As String
Dim Stripe2 As String
Dim Invoice As String
Dim Zip As String
Dim BankAccount As String
Dim RoutingNumber As String
Dim Created As String
Dim PaymentType As Integer
End Structure

Public Function Authorize(ByVal payment As transDetails) As authResultsStructJust because your type definitions are identical doesn't make the compiler think its dealing with the same types. Put the structure definition in a common code file in the app. That way the page and the code behind know they are dealing with the same type definition.
That's sounds like what I need to do. Is there a way to store data definitions so both aspx and dlls can share it?? I'm new to .net.

Thanks
fishin
Sure, define the struct in the dll and set a reference to the DLL in your project with the ASPX pages.
I'm not sure how to do that, can you show me the syntax?

Les
You do it in the GUI. Open your web project with the ASPX pages and then add your DLL project. Click on references in solution explorer -> Right Click ADD Reference click on Projects and then set the reference. Alternatively you could sign the DLL and then install it in the GAC and set a reference to it. Either way could be appropriate if you are using the DLL as a global object for several projects.

0 comments:

Post a Comment