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

When that code is executed

Hello,

I have a function "DoSomething" that it is called from the constructor and
also from the code like in a click event. Is there a way to know, from my
DoSomething function, who has call this function? ex.:

Sub DoSomething
If Call = "New" then
'I am from Sub New
Else
'I am from some where else
End IF

End Sub

Hope that I am clear
Feb 4 '08 #1
4 801
"Marc R." <Ma***@discussions.microsoft.comschrieb:
I have a function "DoSomething" that it is called from the constructor and
also from the code like in a click event. Is there a way to know, from my
DoSomething function, who has call this function? ex.:

Sub DoSomething
If Call = "New" then
'I am from Sub New
Else
'I am from some where else
End IF

End Sub
No, there is no way to do that. However, you can add a parameter to your
procedure indicating from where it has been called.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 4 '08 #2
Though you could (throught reflection or by providing an explicit argument)
this would be really IMO a bad thing to do (what if you want then to call
from a third place or if you change the caller name or whatever).

My personal preference would be to split this having :
- a method that contains the common code
- a method that calls this common code + what is specific to the "new" case
- a method that calls this common code + what is specific to the "click"
case

Then just call the correct method from the constructor and the click event.

It models closely the situation you have that is you want to call common
code from both places but each place will call its own broadest work that in
turn calls common work to be done (instead of having each place calling
common code and deciding in this common code that you should finally do only
this or that because you have been called from a particular location)...

--
Patrice

"Marc R." <Ma***@discussions.microsoft.coma écrit dans le message de news:
5C**********************************@microsoft.com...
Hello,

I have a function "DoSomething" that it is called from the constructor and
also from the code like in a click event. Is there a way to know, from my
DoSomething function, who has call this function? ex.:

Sub DoSomething
If Call = "New" then
'I am from Sub New
Else
'I am from some where else
End IF

End Sub

Hope that I am clear

Feb 4 '08 #3
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in
news:eF**************@TK2MSFTNGP02.phx.gbl:
"Marc R." <Ma***@discussions.microsoft.comschrieb:
>I have a function "DoSomething" that it is called from the
constructor and also from the code like in a click event. Is there a
way to know, from my DoSomething function, who has call this
function? ex.:

Sub DoSomething
If Call = "New" then
'I am from Sub New
Else
'I am from some where else
End IF

End Sub

No, there is no way to do that. However, you can add a parameter to
your procedure indicating from where it has been called.
You can use reflection to find this information out correct?

--
sp**********@rogers.com (Do not e-mail)
Feb 4 '08 #4
[cut]
>
You can use reflection to find this information out correct?

Yes but IMO it would be a wrong approach. The truth is that he just don't
want to call the same code so IMO the OP best bet would be to call two
distinct procedures (each one calling in turn the same procedure so that
they share same of the same code and then the code that is specific to each
case).
Feb 5 '08 #5

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

Similar topics

5
by: Jerzy Karczmarczuk | last post by:
I thought that the following sequence gl=0 def gen(x): global gl gl=x yield x s=gen(1)
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
9
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
7
by: Don | last post by:
Is there any way to check, in code, whether that code is being executed because of a compile as opposed to being executed because someone is just running the program? - Don
60
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this....
10
by: samuelberthelot | last post by:
Hi, I have the following code that shows up a div with an animated gif inside, executes a cpu intensive function using setTimeout and then hide the div again: getEl('divWaiting').style.display...
8
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
2
by: Mirko Vogt | last post by:
Hey, it seems that the socket-module behaves differently on unix / windows when a timeout is set. Here an example: # test.py import socket...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
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...

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.