Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created a class and for one of its property I want to assign a value calculated with a function like this ...
the problem is that property is always 0

Public Property nrZileLucratoare() As Decimal
    Get
        Return m_nrZileLucratoare
    End Get
    Set(ByVal value As Decimal)
        m_nrZileLucratoare = calcZileLucratoare()
    End Set
End Property

Public Function calcZileLucratoare()
    calcZileLucratoare = 20
    Return calcZileLucratoare
End Function



[Edited]Code is wrapped in "pre" tags[/Edited]
Posted
Updated 19-May-11 23:36pm
v2

Why are you calling the method from the set clause? When you say

propertyx = 1


in your code, propertyx should be = 1, not a calculated value.

You should actually do this:

nrZileLucratoare = calcZileLucratoare()


where the set clause looks like this:

Set(ByVal value As Decimal)
    m_nrZileLucratoare = value
End Set
 
Share this answer
 
Strange way of setting a property?

The reason why it is returning you '0' is because you havent told it to set the value.

if you set it, it will be 20.

VB
nrZileLucratoare = 0
        MsgBox(nrZileLucratoare.ToString())


I dont understand why you are using the property this way though :(
 
Share this answer
 
That's pointless since setting the property has no effect.
I'd recommend something like;
VB
Public Property nrZileLucratoare() As Decimal
    Get
        Return calcZileLucratoare()
    End Get
End Property

Public Function calcZileLucratoare()
    calcZileLucratoare = 20
    Return calcZileLucratoare
End Function



Hope this helps,
Fredrik Bornander
 
Share this answer
 
Comments
Daniel Crosman 20-May-11 5:51am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900