• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Passing enumerators between forms

The different forms in my app use the name enumerators, thus it seems logical to put the enumerators in a class and then pass them to the forms that need them.  Can't quite figure out how to perform this.  I need to know how to pass the enumerations or iterate them from the class.  Any help appreciated.

V Whitehead
1 Solution
Jacques Bourgeois (James Burger)PresidentCommented:
I suppose that you meant "same enumerators" instead of "name enumerators".

The best way would be to create constructors that receive the enumerator(s) as a parameter for the form that needs some. Simply add a New method that requires the proper parameter(s), and pass the enumerator(s) to the constructor when you instantiate your object. Doing so, you lose the standard constructor without parameters that is needed for the Form Designer to work, so you will need to add it also. Be sure to keep the call to InitializeComponents that the designer adds for you when you create a New method, this is necessary for the controls to show on the form.

This is the best way to do go, because only the forms that need them will have access to them. But it is not always possible to do so, because one form could be called by another one that does not have access to the required enumerator(s).

In such a case, Declare the enumerators in a module, as Public variables. A module is the way, in VB.NET, to have information available everywhere in the application. See it as a static class if you know the concept from another language. Once instantiated, Public variables in a module are visible everywhere in the Project simply by calling their name.
käµfm³d 👽Commented:
By "enumerators" do you mean enums or actual enumerators?
vaughnwhiteheadAuthor Commented:

Both solutions worked fine, I guess that I will go with the module, as some of the forms will need up to 8 different enums, and I don't want to pass that many to a New constructor.
Again thanks

V Whitehead
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now