Changing variable in different class
Looking for the best way to update a variable in a different class. Below is a rough outline of the situation.
I am wondering if in fnSendEmailTo if I can access the Property in CB? If not, how would you do something like this?
Code:
file: CB.vb
----------------------------
Imports Project.Functions
Public Class CB
Private _CurrentEmailsSentCount As Integer = 0
Private _ID As Integer = 23
Public Property CurrentEmailSentCount() As Integer
Get
Return _CurrentEmailsSentCount
End Get
Set(value As Integer)
_CurrentEmailsSentCount = value
End Set
End Property
Public Function fnStart() As String
CurrentEmailSentCount = fnGetJobPostingID_EmailsSentCount(_ID)
Return sRetVal
End Function
End Class
file: Functions.vb
----------------------------
Public Class Functions
Public Shared Function fnSendEmailTo(...various parameters..) As String
'... code
If iEmailSent = 1 Then
'update the _CurrentEmailsSentCount variable here from class CB
CurrentEmailSentCount += 1
End If
'... code
End Function
End Class
Re: Changing variable in different class
you could make the property shared:
vb Code:
Public Class CB
Private Shared _CurrentEmailsSentCount As Integer = 0
Private _ID As Integer = 23
Public Shared Property CurrentEmailSentCount() As Integer
Get
Return _CurrentEmailsSentCount
End Get
Set(ByVal value As Integer)
_CurrentEmailsSentCount = value
End Set
End Property
Public Function fnStart() As String
CurrentEmailSentCount = fnGetJobPostingID_EmailsSentCount(_ID)
Return sRetVal
End Function
End Class
vb Code:
Public Class Functions
Public Shared Function fnSendEmailTo(...various parameters..) As String
Dim iEmailSent As Integer = 1
'... code
If iEmailSent = 1 Then
'update the _CurrentEmailsSentCount variable here from class CB
CB.CurrentEmailSentCount += 1
End If
'... code
End Function
End Class
Re: Changing variable in different class
why make it shared? It's already public... and exposed through the property... if you want to update it, then you need a reference to the instance that you want to update...
-tg
Re: Changing variable in different class
Making it shared could have some negative consequences. After all, if you did that, you wouldn't even be ABLE to have different instances of that class. At least, they wouldn't be able to work the way they currently do. On the other hand, with a name like CurrentEmailSentCount, perhaps this is a class where there will never be more than one instance anyways, in which case a Shared item would make sense.
Re: Changing variable in different class
Quote:
Originally Posted by
Shaggy Hiker
On the other hand, with a name like CurrentEmailSentCount, perhaps this is a class where there will never be more than one instance anyways, in which case a Shared item would make sense.
that was my guess too. i couldn't answer sooner... i was busy