BlakeMcKenna
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 AddUpdateRefCellDispEquipm ent()
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(txtCDDisplayUncertain ty.Text)
clsRCD.CDUncertainty = CDec(txtCDCDUncertainty.Te xt)
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(cl sRCD) <--- Line in question
Catch ex As Exception
strErr = gfrmID & "/AddUpdateRefCellDispEqui pment() - " & 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?
'Form Class Call
Dim clsRCD As New clsRefCellDisp
Private Sub AddUpdateRefCellDispEquipm
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.
clsRCD.DisplayModel = txtCDDisplayModel.Text
clsRCD.DisplaySN = txtCDDisplaySerialNO.Text
clsRCD.DispUncertainty = CDec(txtCDDisplayUncertain
clsRCD.CDUncertainty = CDec(txtCDCDUncertainty.Te
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(cl
Catch ex As Exception
strErr = gfrmID & "/AddUpdateRefCellDispEqui
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
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?
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?
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
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.
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.
ASKER
The Business Layer is a separate project within my solution. The Class is within the Main project.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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:
As long as both your main project and the BL can see the definition of that class, then you should be set.
Public Function AddUpdateRefCellDisp(ByVal cls As clsRefCellDisp) As Boolean
End Function
As long as both your main project and the BL can see the definition of that class, then you should be set.