Using ByRef keyword
-
I am writing a class that should have the ability to modify the members of another class. I am wondering if ByRef will allow this functionality. Thanks for any info...
-
I am writing a class that should have the ability to modify the members of another class. I am wondering if ByRef will allow this functionality. Thanks for any info...
ByRef can only be used in Sub and Function parameter passing. If ObjectB is passed to a method in ClassA ByRef, then that method can get to that instance of ObjectB.
Dim b As Integer = 23
ModifySomething(b)
Debug.WriteLine("The value of b is: " & b.ToString())Private Sub ModifySomething(ByRef someInt As Integer)
someInt = 99
End Sub-----8<------------------------------------------------
Output:
The value of b is: 99RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
ByRef can only be used in Sub and Function parameter passing. If ObjectB is passed to a method in ClassA ByRef, then that method can get to that instance of ObjectB.
Dim b As Integer = 23
ModifySomething(b)
Debug.WriteLine("The value of b is: " & b.ToString())Private Sub ModifySomething(ByRef someInt As Integer)
someInt = 99
End Sub-----8<------------------------------------------------
Output:
The value of b is: 99RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
So, is the following idea permitted?
Public Class Form1
Private Function SaveObject()
Object.Save()
End Private
End ClassPublic Class Object
' ... members, properties and constructors ...Public Property DataID as Integer ' ... Get and Set the DataID End Property Public Sub Save() Dim DataSaver as New ObjectDataLogic DataSaver.Save(Me) End Sub
End Class
Public Class ObjectDataLogic
' ... members, properties and constructors ...
Public Sub Save(ByRef Object as Object)
' ... save to the database and return get the new ID
Object.DataID = NewID
End Public
End ClassI want the data logic and the business object on two seperate tiers. Would this be considered good design or is there a better way to accomplish this? Any issues that could arise from this approach? I am seeking any additional resources that are out there! Thanks!
-
I am writing a class that should have the ability to modify the members of another class. I am wondering if ByRef will allow this functionality. Thanks for any info...