Newbie question - Global Structure Type

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hello all

If I have some structure data types, structure... end structure that I use
for all of my classes and in the main form, how do I make it into component
so that everyone can reference to it and I can re-use it later for other
projects? Thanks

Sam
 
Probalby the easiest way is to creat a module and delcare the structures
public in that module. You can then include the modue to each project by
adding the module to the projects. You could also create a class library
with the structures delcared and create a .dll assembly from this library.
That also could be added to your projects.
 
Hi Dennis

Does it mean that I have to declare other variables in other classes as then
new class name then reference it to a structure in a the dll?
For example, in other classes when I declare a variable references to this
structure as Dim MyVar1 as Class1.MyStructure?
Public Class Class1

Public Structure MyStructure

Var1 as Integer

Var2 as Integer

End Structure


End Class
 
Sam,
No you can simply add a new file to your class library then declare the
structures at the file level.

I normally add a Class called "MyStructure" to get the MyStructure.vb file,
then replace the "Public Class MyStructure" with "Public Structure
MyStructure" likewise "End Class" with "End Structure", so I wind up with:

---x--- begin MyStructure.vb ---x---
Option Strict On
Option Explicit On
Public Structure MyStructure

Var1 as Integer

Var2 as Integer

End Structure
---x--- end MyStructure.vb ---x---

Most of the time I have a single Structure, Class, Enum or Module per file,
however I may have multiple Delegates per file. Or the Delegate may be in
the file that it is most closely associated with. For example I would put
System.EventHandler & System.EventArgs in the EventArgs.vb file.

I only nest a type (Structure, Class, Enum, Module, Delegate) within another
type when the nested type is a specific implementation detail of the outer
type.

Hope this helps
Jay
 
Jay,

Thanks so lots. It helps

Sam


Jay B. Harlow said:
Sam,
No you can simply add a new file to your class library then declare the
structures at the file level.

I normally add a Class called "MyStructure" to get the MyStructure.vb file,
then replace the "Public Class MyStructure" with "Public Structure
MyStructure" likewise "End Class" with "End Structure", so I wind up with:

---x--- begin MyStructure.vb ---x---
Option Strict On
Option Explicit On

---x--- end MyStructure.vb ---x---

Most of the time I have a single Structure, Class, Enum or Module per file,
however I may have multiple Delegates per file. Or the Delegate may be in
the file that it is most closely associated with. For example I would put
System.EventHandler & System.EventArgs in the EventArgs.vb file.

I only nest a type (Structure, Class, Enum, Module, Delegate) within another
type when the nested type is a specific implementation detail of the outer
type.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top