In vb.net i create two classes. In First class i define a property to return a single value and in second class define one function it get values from property and return a single value. I call the function when i click the button.
I create a object for property and use this object to call the property when i press enter in form after entering the number in text box. Values can be insert properly using first class(property) and it return safely. But in second class i create a object for Property and access the variable from first class (that is property defined class). It store only zero here, so it return zero value.
But if i give shared as variable in first class, this value can access in function through classname.varia blename, because of shared.
I need to access the variable through object. My code is below. Let me know any wrong in this code
I create a object for property and use this object to call the property when i press enter in form after entering the number in text box. Values can be insert properly using first class(property) and it return safely. But in second class i create a object for Property and access the variable from first class (that is property defined class). It store only zero here, so it return zero value.
But if i give shared as variable in first class, this value can access in function through classname.varia blename, because of shared.
I need to access the variable through object. My code is below. Let me know any wrong in this code
Code:
Public Class clsProperty
Public m_Value As Integer
Public Property InsertValues() As Integer
Get
Return m_Value
End Get
Set(ByVal value As Integer)
m_Value = value
End Set
End Property
End Class
Public Class clsFunctions
Public Function DisplayValue() As Integer
Try
Dim objProp As New clsProperty
Dim returnValue As Integer
returnValue = objProp.m_Value
Return returnValue
Catch ex As Exception
Throw ex
End Try
End Function
End Class
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Try
Dim objProperty As New clsProperty
Dim objFunction As New clsFunctions
objProperty.InsertValues = Val(txtInput.Text)
txtOutput.Text = objFunction.DisplayValue()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Comment