-
May 8th, 2012, 09:44 AM
#1
dynamic variable names
Hello there,
I have a single module that can be called by several modules.
for each of these several modules, I have Globale variables related to them.
if I call my unique module with Module1, I want the single Module to work with Module1 Global variable, if it's called from Module2, then we use module 2...
short example:
Code:
private void Module1()
{
SingleModule(ModuleName)
}
private void Module2()
{
SingleModule(ModuleName)
}
private void SingleModule(string ModuleName)
{
if ( GlobaleVariable == true)
GlobalVariable = false;
}
so in this example, the variable name of [GlobalVariable] should differ based on the module calling the Single Module.
I know I could get around by using a SWITCH / CASE in my SingleModule for each seperated module calling it, but there's gotta be a better way, since the use of a SWITCH /CASE would involve programming change in my SingleModule each time I create another module calling it...
your help would be greatly appreciated...
thanks.
-
May 8th, 2012, 09:50 AM
#2
Re: dynamic variable names
Firstly, try to avoid global variables wherever possible.
Secondly, why not just pass a reference to the relevant variables when calling the module?
-
May 8th, 2012, 11:06 AM
#3
Re: dynamic variable names
Hello Peter,
Thanks for the quick response btw.
the reson I was not using a reference is that since I'm quite new to all this, I was not aware of this REF method, you pointed me to the right direction, and everything works now
thanks!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|