Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

Accessing Class data from different Layers?

I have created a Class in which it contains a bunch of Properties. In the UI of my app, I load a bunch of form values into this Classes properties. Now, what I want to do is pass this entire Class over to my Business and Data Layers. See below for what I want to do!

    'Form Class Call

    Dim clsRCD As New clsRefCellDisp

        Private Sub AddUpdateRefCellDispEquipment()
        Try
            Dim strIOType As String = ""
 
            clsRCD.CellDispName = txtCDDisplayName.Text
            clsRCD.Capacity = txtCDCapacity.Text
            clsRCD.LoadCellModel = txtCDLoadCellModel.Text
            clsRCD.LoadCellSN = txtCDLoadCellSerialNO.Text
            clsRCD.CellUncerntainty = CDec(txtCDCellUncertainty.Text)
            clsRCD.DisplayModel = txtCDDisplayModel.Text
            clsRCD.DisplaySN = txtCDDisplaySerialNO.Text
            clsRCD.DispUncertainty = CDec(txtCDDisplayUncertainty.Text)
            clsRCD.CDUncertainty = CDec(txtCDCDUncertainty.Text)
            clsRCD.NIST = txtCDNIST.Text
            clsRCD.CalDate = dtCalDate.Value
            clsRCD.Interval = CInt(cmbInterval.Text)
            clsRCD.NextCalibration = dtNextCalDate.Value
            clsRCD.TechID = txtCDTechID.Text
            clsRCD.Newest = CInt(txtCDNewest.Text)

            strIOType = BL.AddUpdateRefCellDisp(clsRCD)          <--- Line in question

        Catch ex As Exception
            strErr = gfrmID & "/AddUpdateRefCellDispEquipment() - " & ex.Message
            MessageBox.Show(strErr, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub



For the line in question, I tried to create this function in my Business Layer where in the Function signature I tried to define a Class object but it would not let me. See below.

        Public Function AddUpdateRefCellDisp(ByVal cls As Object) As Boolean

        End Function


I want to replace "Object" above with "Class". Apparently it's not possible. So how do I reference my class that I instantiated in my Form Class?
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Your Business layer needs to reference the assembly that contains the definition of your class. I'm guessing they are not currently in the same assembly?
Avatar of BlakeMcKenna

ASKER

How do I do that? Is that the same as declaring an instance of that class within each layer, i.e.

    Private clsRCD As New clsRefCellDisp
How is your project structured? Is your business layer in a separate project from your application?

You business layer won't know what a clsRefCellDisp object is unless it exists in the same project, or it references the assembly where the class is defined.
The Business Layer is a separate project within my solution. The Class is within the Main project.
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland 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
Well, I actually put it into the Business Layer project as a Reference...but what I'm not sure is, how do I pass the Class Property values into the Business Layer now that the Class is part of the Project.
Screenshot.jpg
The type for your custom object is "clsRefCellDisp", so that is what you would specify as the type for the parameter in your BL. Like:
Public Function AddUpdateRefCellDisp(ByVal cls As clsRefCellDisp) As Boolean

End Function

Open in new window


As long as both your main project and the BL can see the definition of that class, then you should be set.