473,566 Members | 2,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflecting on a basic variable and procedure name.

I have two tasks that I expect will be straight forward to anyone with
reflection skills.

1. To return the the name of an object instance (not type) determined at run
time.

For example, I would like to call a function that takes a basic variable and
writes to the debug window the name of the variable and value.

Dim myNumber As Integer = 12
Dim firstName as String = "Barry"

OutputFieldAndV alue(myNumber)
OutputFieldAndV alue(firstName)

' Gives something like
myNumber : 14
firstName : Barry

Sub OutputFieldAndV alue( _
ByVal field As Object)

Dim pad AS Integer = 10
Dim tabs As String = StrDup(1, Tab)

Dim fieldName As String = "Not yet Implemented"
Dim value As String = field.ToString( )

Debug.WriteLine (fieldName.PadR ight(pad) & ":" _
& tabs & value.ToString. PadLeft(pad))
End Sub

What could "Not yet Implemented" be replaced with?

2. The name of the current procedure.

Eg
Function FunnyFunction() as Object
Debug.WriteLine ( ' some statement that out puts "FunnyFunct ion" ' )
End Function
Jul 21 '05 #1
2 2184
John Bentley <no*****@nowher e.com> wrote:
I have two tasks that I expect will be straight forward to anyone with
reflection skills.

1. To return the the name of an object instance (not type) determined at run
time.

For example, I would like to call a function that takes a basic variable and
writes to the debug window the name of the variable and value.

Dim myNumber As Integer = 12
Dim firstName as String = "Barry"

OutputFieldAndV alue(myNumber)
OutputFieldAndV alue(firstName)
Nope, neither of these are going to happen.

When you pass a value, that's all that gets passed - a value. There's
no difference between
OutputFieldAndV alue (myNumber);
and
OutputFieldAndV alue (12);

as far as the OutputFieldAndV alue method is concerned.
2. The name of the current procedure.

Eg
Function FunnyFunction() as Object
Debug.WriteLine ( ' some statement that out puts "FunnyFunct ion" ' )
End Function


You can use the StackTrace class for this. Be aware that the JIT may do
interesting things to stack traces though.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
> -------------------------------------------------
Jon Skeet wrote (at this indent level):
------------------------------------------------- John Bentley <no*****@nowher e.com> wrote:
I have two tasks that I expect will be straight forward to anyone
with reflection skills.

1. To return the the name of an object instance (not type)
determined at run time.

For example, I would like to call a function that takes a basic
variable and writes to the debug window the name of the variable and
value.

Dim myNumber As Integer = 12
Dim firstName as String = "Barry"

OutputFieldAndV alue(myNumber)
OutputFieldAndV alue(firstName)
Nope, neither of these are going to happen.
When you pass a value, that's all that gets passed - a value. There's
no difference between
OutputFieldAndV alue (myNumber);
and
OutputFieldAndV alue (12);

as far as the OutputFieldAndV alue method is concerned.


:(
2. The name of the current procedure.

Eg
Function FunnyFunction() as Object
Debug.WriteLine ( ' some statement that out puts "FunnyFunct ion"
' ) End Function
You can use the StackTrace class for this.


That's the tip off! Thanks once more Jon.
Be aware that the JIT may
do interesting things to stack traces though.


With this awareness firmly *Not* in my mind I then came up with:

Imports System.Diagnost ics

Function ThisProcedureNa me() As String
Dim st As New StackTrace()
Dim sf As New StackFrame()

' The procedure we are interested in is not this one but
' the one that called this one. That's one down on the stack.
sf = st.GetFrame(1)

Return sf.GetMethod.Na me
End Function

Sub MyProcedureName ()
Debug.WriteLine ("Name of this procedure: " _
& ThisProcedureNa me())
End Sub

Keywords: Current Procedure Name
Jul 21 '05 #3

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

Similar topics

3
6810
by: claus.hirth | last post by:
Does the term 'host variable' cover a variable locally declared in a SQL-PL stored procedure? I am asking this question in the context of the SELECT INTO statement.
14
2489
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic types in objects. But if they are objects why it´s need this conversion? Aren´t objects (basic types) like Java?
4
6066
by: Steve Franks | last post by:
I'm new to ASP.NET and working with the 2.0 beta. As a classic ASP developer I have a lot of code that looks like this: sql = "insert into x values(" sql = sql & val1 & ", " & val2 & ", ' " & strVal3 & " ', " & val4 & ")" Which of course gets very messy. As I understand it there is a way to use a placeholder string with question marks...
2
247
by: John Bentley | last post by:
I have two tasks that I expect will be straight forward to anyone with reflection skills. 1. To return the the name of an object instance (not type) determined at run time. For example, I would like to call a function that takes a basic variable and writes to the debug window the name of the variable and value. Dim myNumber As Integer...
3
1755
by: | last post by:
Hi all, I have a question on reflection Lets say I have a custom object called Address. Now, lets say I have a string variable that holds the name of a variable in the object such as "State.StateCode". How can I reflect upon the Address object so as to echo the value contained in the string variable. Something like:- Dim add as new...
7
4706
by: garyusenet | last post by:
This is the first time i've worked with openfile dialog. I'm getting a couple of errors with my very basic code. Can someone point out the errors in what i've done please. ========================================== using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
14
1833
by: MartinRinehart | last post by:
Working on parser for my language, I see that all classes (Token, Production, Statement, ...) have one thing in common. They all maintain start and stop positions in the source text. So it seems logical to have them all inherit from a base class that defines those, but this doesn't work: import tok class code: def __init__( self, start,...
20
12705
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The AutoExec macro calls a function "InitApplication" which, in turn, calls a function to set the value of a global string variable
3
7703
by: dmorand | last post by:
I'm very new to stored procedures so this is probably something very dumb. I want to pass a name of a table to be created to my stored procedure. I'm using the variable @tableName in the code below but I'm getting an error: Server: Msg 170, Level 15, State 1, Procedure usp_CodeGreyData, Line 22 Line 22: Incorrect syntax near '@tableName'....
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.