"John Dann" <ne**@prodata.co.uk> schrieb
On Fri, 13 Feb 2004 16:57:38 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:
You didn't specify where the compiler should look for the
structure.
In Class2:
dim var as Class1.ExampleStructure
Many thanks. I did try instantiating class1 in class2 and using
the object name to help point to the structure definition, but this
just gave an error. I didn't think to use the class name itself.
You must distinguish between a class and an object here:
The place of the structure is only the place of it's declaration. This does
/not/ mean that an object of type Class1 contains a field of the type
ExampleStructure. You would have to add a field of that type:
class class1
structure ExampleStructure
'...
end structor
public Member1 as ExampleStructure
end class
Now you can write:
dim o1 as new class1
o1.member1.a = 17
I guess this is a sort of generic difference of VB.Net from VB6,
where AFAICR one doesn't use the class name in other components,
other than for instantiating a new object.
It was the same in VB6:
1. Create a new activeX dll project
2. Add two more classes
3. Within Class1 /and/ Class2 add
Public Type test
x As Integer
End Type
4. Within Class3 add
Sub a()
Dim y As test
End Sub
You get an ambiguous name error. Changing it to
Dim y As Class1.test 'or Class2.test
makes the type unambiguous.
The only difference is that, when not specifiying the class name, VB6
automatically searches for the type in all classes. The type was "global".
In VB.NET you have to specify the location because it is not "global". If
there is no reason to put the structure declaration in Class1, put it
outside the class as Herfried suggested. Alternatively (I don't recommend
it!), import Class1:
Imports BaseNamespace.Class1
Class Class2
dim var as test
end class
Now the compiler also looks for the type in the imported class Class1.
--
Armin
How to quote and why:
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html