• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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?
0
BlakeMcKenna
Asked:
BlakeMcKenna
  • 4
  • 3
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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?
0
 
BlakeMcKennaAuthor Commented:
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
0
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
BlakeMcKennaAuthor Commented:
The Business Layer is a separate project within my solution. The Class is within the Main project.
0
 
Carl TawnSystems and Integration DeveloperCommented:
If the class needs to be shared by both projects then you would be better off either putting it in the Business layer project itself, or moving it into a separate class library project and referencing that project from the business layer and your main project.
0
 
BlakeMcKennaAuthor Commented:
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
0
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now