473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Scope of structure declarations

I'd like to use the same different variables of the same structure in
multiple classes etc. But even though I declare a structure as eg:

Public Structure ExampleStructure
Dim A as short
Dim B as short
etc
End Structure

in one class and works OK within that class, I'm getting a 'Type
'ExampleStructure' is not defined' error when I go to declare a
variable of type ExampleStructure in any class/form etc file other
than the one in which the structure is initially defined.

What am I doing wrong please?

John Dann
Nov 20 '05 #1
7 1169
Sorry, an extra 'same' was left in the first line. What I emant to say
was:

On Fri, 13 Feb 2004 15:26:21 +0000, John Dann <ne**@prodata.co.uk>
wrote:
I'd like to use the different variables of the same structure in
multiple classes etc. But even though I declare a structure as eg:

Public Structure ExampleStructure
Dim A as short
Dim B as short
etc
End Structure

in one class and works OK within that class, I'm getting a 'Type
'ExampleStructure' is not defined' error when I go to declare a
variable of type ExampleStructure in any class/form etc file other
than the one in which the structure is initially defined.

What am I doing wrong please?

John Dann


Nov 20 '05 #2
"John Dann" <ne**@prodata.co.uk> schrieb
I'd like to use the different variables of the same structure in
multiple classes etc. But even though I declare a structure as
eg:

Public Structure ExampleStructure
Dim A as short
Dim B as short
etc
End Structure

in one class and works OK within that class, I'm getting a 'Type
'ExampleStructure' is not defined' error when I go to declare a
variable of type ExampleStructure in any class/form etc file
other than the one in which the structure is initially defined.

What am I doing wrong please?

You didn't specify where the compiler should look for the structure.

In Class2:
dim var as Class1.ExampleStructure
assuming that Class1 contains the structure.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #3
* John Dann <ne**@prodata.co.uk> scripsit:
I'd like to use the same different variables of the same structure in
multiple classes etc. But even though I declare a structure as eg:

Public Structure ExampleStructure
Dim A as short
Dim B as short
etc
End Structure

in one class and works OK within that class, I'm getting a 'Type
'ExampleStructure' is not defined' error when I go to declare a
variable of type ExampleStructure in any class/form etc file other
than the one in which the structure is initially defined.

What am I doing wrong please?


Are you sure the structure isn't declared /inside/ another class? Put
it into a separate file called "ExampleStructure.vb" and try again.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
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.

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.

JGD
Nov 20 '05 #5
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb

What am I doing wrong please?


Are you sure the structure isn't declared /inside/ another class?


He is sure it is inside another class.

;-)
--
Armin

Nov 20 '05 #6
"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

Nov 20 '05 #7
* "Armin Zingler" <az*******@freenet.de> scripsit:
What am I doing wrong please?


Are you sure the structure isn't declared /inside/ another class?


He is sure it is inside another class.


I read your other replies...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Vipul Jain | last post by:
Can any one please tell me what is the difference between global scope of an variable and file scope of an variable. Vipul
4
by: Marc Tanner | last post by:
Hello, I am currently working on a eventhandling system or something similar, and have the problem of loosing scope. I have read many interesting posts on this group and the faq article about...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
3
by: fctk | last post by:
are the following rules correct in C89/C90? ---- SCOPE RULES 1) the scope of an identifier declared inside a block is the block in which it is declared; 2) when you have nested blocks...
5
by: Steven T. Hatton | last post by:
This note appears in the discussion of name hiding and uniqueness: §3.3 #4 This note is item #6 in the discussion of "Point of declaration" §3.3.1 #6 What exactly do these statements mean?...
6
by: Subra | last post by:
Hi, If I have the same varible defined in global as well as in local scope, how to access global scope varible in a function having the same local def. #include<stdio.h> static int a=25;...
2
by: Laurent Deniau | last post by:
I would like to know why the following small program does not compile (checked with gcc 4.1.2) and if the compiler behavior is correct: struct A; typedef void (T)(struct A*); void f(void) {...
6
by: Szabolcs Borsanyi | last post by:
Dear all, I'd like to define a macro that expands to a struct-or-union-specifier. Inside of this struct there shall be a named structure. Alas, the struct tag inside the other unnamed structure...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.