473,385 Members | 1,465 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,385 software developers and data experts.

Global type variables in VB.NET

My situation is that I have a custom user control that I have built into a
DLL and put it on the "USER CONTROLS" part of the toolbox, so I can drag it
into a form whenever I need it.
The problem is that, for a variety of reasons, I need to "see" a variable in
all the SUBs that exist in my user control class that is defined in my
startup module of my program. Here's a code snippet:

Imports MyUserControlLibrary
Module Startup
public myGlobalArrayList as arraylist
public sub main()
.... Application.Run(Form1)
end sub
end module

I need to see myGlobalArrayList EVERYWHERE including the subs in
MyUserControlLibrary (which is a dll I built containing my custom stuff). I
tried making it a public variable (as in this example), I've tried a
separate class where I define a public shared property. But in all cases I
can see myGlobalArrayList in my application subs, but NOT in the subs within
the MyUserControlLibrary dll.
When I was testing the routines in MyUserControlLibrary I had them as the
*.VB files in my current application and everything worked fine. When I
broke them out into a separate module and compiled them into a dll they
could no longer see the variable.

Is there any way I can make myGlobalArrayList visible to the routines in the
dll library???

Thanks for any suggestions...
Nov 21 '05 #1
4 1496
John,

Would you not first start with a more simple approach.
A user control is for a self made control (what nobody does) or a from
Control derived class. A control is a class that acts to do UI handling.

In that can be a reason for an Arrayclass, however than probably not the
best approach, because there are standard when they are used collections in
a control.

You can make a "compenent" of course, however I would first try to make my
program with what I want to use. Than I can decide to make a compenent from
it for future use.

Just my thought when I readed your message.

Cor
Nov 21 '05 #2
Hi Cor,

Thanks for the reply. You misread the post... I am, in fact, creating a
user control that is derived from (ie: inherits) the LABEL control. Within
that usercontrol I have an arraylist which must be accessable from anywhere
in the program.

I did find a solution to my problem and I want to post it here for others
who may be interested. I used a SINGLETON PATTERN class (search google for
that for more info). Basically, a singleton pattern class is a class with
only one instance. Essentially the constructor of the class is private (not
public like regular classes) so it can only be constructed from within
itself. But, you ask, how can you access the class if you can't access the
constructor? Good question. The answer is that you have a PUBLIC SHARED
function method that checks if the instance exists yet, and if it does it
returns that instance, if it does not yet exist, it creates an instance and
returns that. Public Shared procedured in a class can be accessed EVEN IF
THE CLASS INSTANCE DOES NOT YET EXIST. So that's how you build the
instance.

Using this technique, whenever you want the class you get the exact same
instance (properties and all). Soooo, this class is perfect for holding
properties that can be accessed globally. This is the solution I used and
it worked flawlessly.

John
"Cor Ligthert" <no************@planet.nl> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
John,

Would you not first start with a more simple approach.
A user control is for a self made control (what nobody does) or a from
Control derived class. A control is a class that acts to do UI handling.

In that can be a reason for an Arrayclass, however than probably not the
best approach, because there are standard when they are used collections
in a control.

You can make a "compenent" of course, however I would first try to make my
program with what I want to use. Than I can decide to make a compenent
from it for future use.

Just my thought when I readed your message.

Cor

Nov 21 '05 #3
Hi Cor,

Thanks for the reply. You misread the post... I am, in fact, creating a
user control that is derived from (ie: inherits) the LABEL control. Within
that usercontrol I have an arraylist which must be accessable from anywhere
in the program.

I did find a solution to my problem and I want to post it here for others
who may be interested. I used a SINGLETON PATTERN class (search google for
that for more info). Basically, a singleton pattern class is a class with
only one instance. Essentially the constructor of the class is private (not
public like regular classes) so it can only be constructed from within
itself. But, you ask, how can you access the class if you can't access the
constructor? Good question. The answer is that you have a PUBLIC SHARED
function method that checks if the instance exists yet, and if it does it
returns that instance, if it does not yet exist, it creates an instance and
returns that. Public Shared procedured in a class can be accessed EVEN IF
THE CLASS INSTANCE DOES NOT YET EXIST. So that's how you build the
instance.

Using this technique, whenever you want the class you get the exact same
instance (properties and all). Soooo, this class is perfect for holding
properties that can be accessed globally. This is the solution I used and
it worked flawlessly.

John
"Cor Ligthert" <no************@planet.nl> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
John,

Would you not first start with a more simple approach.
A user control is for a self made control (what nobody does) or a from
Control derived class. A control is a class that acts to do UI handling.

In that can be a reason for an Arrayclass, however than probably not the
best approach, because there are standard when they are used collections
in a control.

You can make a "compenent" of course, however I would first try to make my
program with what I want to use. Than I can decide to make a compenent
from it for future use.

Just my thought when I readed your message.

Cor

Nov 21 '05 #4
John,
This is the solution I used and it worked flawlessly.

Than I probably misreaded it, I thought that you had a problem

Cor
Nov 21 '05 #5

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

Similar topics

2
by: Otto Wyss | last post by:
I have a string variable g_appname which should be global accessable by any class who whishes. I have defined it as wxString *g_appname = NULL; and fills it later on. Now a friend asked why I...
4
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
5
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used...
13
by: Sunil | last post by:
Hi all, I want to know how good or bad it is using global variables i.e advantages and disadvantages of using global variables. Sunil.
9
by: vivekian | last post by:
Have a couple of global variables of a class type which i have declared and defined in the application. 1. Not sure where should the global variables be placed ? 2. Would i need to forward...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: Gary Herron | last post by:
Jacob Davis wrote: Yuck, YUCK, YUCK! You are breaking *so* many good-programming-practices, I hardly know where to start. First off: A python global is not what you think. There are *no*...
18
by: Bruce | last post by:
When I do this: <input id="someName" type="text"> <script type="text/javascript"> alert(someName.nodeName); </script> Both IE6 and Firefox alert("INPUT"). Why isn't "someName" undefined?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.