dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: How to get CURRENT Sub/Function Name

  1. #1
    Join Date
    Jan 2003
    Posts
    50

    How to get CURRENT Sub/Function Name

    hi gurus,

    is there any ways to find CURRENT sub/function name,

    we can get CURRENT form name by Me.name, in the same ways how can we get current sub/function name

  2. #2
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    I don't think this is possibele unless you insert global variables that you update with names during function/sub calls.
    Marketing our skills - please participate in the survey and share your insights
    -

  3. #3
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Well, I don't think it would be possible.. If so, I don't think it would be easier than declaring a global string variable that will identify the name of the routine for the program..
    Busy

  4. #4
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    As has already been said, you cannot do this. The main reason of course is that your source code is compiled into the application and the actual function names are not necessarily preserved in any form that can be recognised.

    You either have to set a global variable or property at the start of each function/sub or do without I am afraid.
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  5. #5
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    Originally posted by TimCottee
    ... The main reason of course is that your source code is compiled into the application and the actual function names are not necessarily preserved in any form that can be recognised. ...
    Hi Tim,

    It seems to be that this is not totally the case. There is a function called CallByName. This means, there must something that is preserved during compilation.

    I don't know, I have not used that function. I just read it here.
    Anyone?
    Marketing our skills - please participate in the survey and share your insights
    -

  6. #6
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    Indeed callbyname exists but remember that this is also compiled. I am not saying that a function / sub name is totally destroyed but you cannot necessarily expect that it is preserved in the compiled executable as a string. These references may be converted to some intermediate reference or even to a memory address or pointer in the compiled code. CallByName will still work because the compiled reference is still consistent but only within the compiled code.

    Now that may be a simplification as I am no expert on compilation or compiled code but it is definite that there is no simple way to return the name of the current sub/function at runtime unless you do so manually.
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  7. #7
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Not yet implemented in VB.. The fact on the CallByName is that it requires the Object placeholder of the routine and is not applicable with the Standard Module..
    Busy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)