dynamic variable names
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: dynamic variable names

  1. #1
    Join Date
    May 2012
    Posts
    2

    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.

  2. #2
    Join Date
    Jan 2009
    Posts
    596

    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?

  3. #3
    Join Date
    May 2012
    Posts
    2

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center