I thought I understood how this works, but I guess I was wrong:
Up until now I thought using the New Keyword was to create
a new Instance of for example a class, allocating space for its variables.
Without specifing New it only would declare it to something and
if one were to assign it to another instance of the class, only a referece would be passed.
For example:
Now I had assumed that Debug.Print would display "A" (see explanation above),
but it shows "B".
So SomeOtherClass is a reference to SomeClass?
How can I tell VB to make a copy of the class instead of just passing a reference?
SomeOtherClass = New SomeClass doesn't work.
What also interests me:
Is there a difference if I omit the New Keyword in the declaration of SomeOtherClass,
since I both cases only a reference is passed.
Although this is offtopic, I don't wanted to create another Thread for it:
The ArrayList Class for example
Dim AL as New ArrayList
AL(0) = "Bla"
Is the same as
AL.Item(0) = "Bla"
How can I create my own class which also accepts parameters
directly after the Class Instance Variable?
Up until now I thought using the New Keyword was to create
a new Instance of for example a class, allocating space for its variables.
Without specifing New it only would declare it to something and
if one were to assign it to another instance of the class, only a referece would be passed.
For example:
Visual Basic:
Class ClassA
Public VarA as String
Public VarB as String
End Class
Dim SomeClass as New ClassA
SomeClass.VarA = "A"
SomeClass.VarB = "B"
Dim SomeOtherClass as New ClassA
SomeOtherClass = SomeClass
SomeOtherClass.VarA = "B"
Debug.Print(SomeClass.VarA)
but it shows "B".
So SomeOtherClass is a reference to SomeClass?
How can I tell VB to make a copy of the class instead of just passing a reference?
SomeOtherClass = New SomeClass doesn't work.
What also interests me:
Is there a difference if I omit the New Keyword in the declaration of SomeOtherClass,
since I both cases only a reference is passed.
Although this is offtopic, I don't wanted to create another Thread for it:
The ArrayList Class for example
Dim AL as New ArrayList
AL(0) = "Bla"
Is the same as
AL.Item(0) = "Bla"
How can I create my own class which also accepts parameters
directly after the Class Instance Variable?