|
-
Mar 8th, 2012, 11:51 AM
#1
Thread Starter
Fanatic Member
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
Last edited by lleemon; Mar 8th, 2012 at 11:54 AM.
-
Mar 8th, 2012, 12:11 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 8th, 2012, 12:20 PM
#3
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
-
Mar 8th, 2012, 12:51 PM
#4
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.
My usual boring signature: Nothing
 
-
Mar 8th, 2012, 02:08 PM
#5
Re: Changing variable in different class
 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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|