473,473 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is there a Function and Function Argument generic self-reference?

Is there a way for a function to refer to itself generically? I'd like
to use such a thing (should it exist) for convenience and consistency,
not functionality.

For example:

Function Common(Some_String as String) As String
...
End Function

Function Go() As String
Dim Some_String = New String
Common(Go)
....
End Function

Function Stop() As String
Dim Some_String = New String
Common(Stop)
....
End Function

In this example, both Go() and Stop() want to call Common() to take
care of some common code. Being Go() an Stop() are instantiated
objects, they pass themselves as the argument. The question is, is
there a way for the code to be the same, something like Common(Me),
where Me is a reference to the function itself. Dimming a new object
(of common name) defeats the purpose, however.

-----

Is there a way of refering to the functions arguments? For example,
this would be what i would want to do:

Sub Reset(Obj As Object, First_Name As String, Last_Name as String,
Address As String)

Dim Counter As Integer

For Counter = 1 to Reset.Arguments.Count -1

Set Obj.Parameters(Reset.Arguments(Counter).Name).Valu e =
Reset.Arguments(Counter).Name

Next Counter

End Function
B.

Jun 12 '06 #1
2 1734

Ma***********@ThePentagon.com wrote:
Is there a way for a function to refer to itself generically? I'd like
to use such a thing (should it exist) for convenience and consistency,
not functionality.


Well, if I understan what you're asking, you could achieve something
like this with inheritance. You would create a base class containing
the common code and then inherit from it. Then, its a matter of
calling your base class implementaion... Something like:

Option Strict On
Option Explicit On

Module Module1

Private Class Common
Public Overridable Function Go() As String
Return "MyBase.Go ()"
End Function

Public Overridable Function [Stop]() As String
Return "MyBase.Stop ()"
End Function
End Class

Private Class MyImplementation
Inherits Common
Public Overrides Function Go() As String
Return "MyImplementation.Go ()" & " - " & MyBase.Go()
End Function

Public Overrides Function [Stop]() As String
Return "MyImplementation.Stop ()" & " - " & MyBase.Stop()
End Function

End Class

Sub Main()
Dim imp As New MyImplementation

Console.WriteLine(imp.Go())
Console.WriteLine(imp.Stop())
End Sub

End Module

--
Tom Shelton [MVP]

Jun 12 '06 #2
Tom Shelton wrote:
Ma***********@ThePentagon.com wrote:
Is there a way for a function to refer to itself generically? I'd like
to use such a thing (should it exist) for convenience and consistency,
not functionality.


Well, if I understan what you're asking, you could achieve something
like this with inheritance. You would create a base class containing
the common code and then inherit from it. Then, its a matter of
calling your base class implementaion... Something like:

Option Strict On
Option Explicit On

Module Module1

Private Class Common
Public Overridable Function Go() As String
Return "MyBase.Go ()"
End Function

Public Overridable Function [Stop]() As String
Return "MyBase.Stop ()"
End Function
End Class

Private Class MyImplementation
Inherits Common
Public Overrides Function Go() As String
Return "MyImplementation.Go ()" & " - " & MyBase.Go()
End Function

Public Overrides Function [Stop]() As String
Return "MyImplementation.Stop ()" & " - " & MyBase.Stop()
End Function

End Class

Sub Main()
Dim imp As New MyImplementation

Console.WriteLine(imp.Go())
Console.WriteLine(imp.Stop())
End Sub

End Module

--
Tom Shelton [MVP]


Firstly, thanx for responding. I appreciate it.
Secondly, sorry for using "stop" as a function name. Silly me using a
keyword. :)
Thirdly, I have no real working knowledge with inheritance, and do not
understand what the override did exactly.
Finally, why are you returning them in quotes? I chose string as an
object, not because i wanted a string.

Here's what i am trying to do. I have a number of database procedures
(DB2) that will return CURSORs to my DB2Commands for the DataAdaptors
to use. There are quite a few of them, and i need to specify the
parameters for each. But, some code is the same. So, for right now, the
basic is something like:

Sub Stored_Procedure_Common(ByVal Command As DB2Command)
Command.CommandType = CommandType.StoredProcedure
Command.Parameters.Add("OUT_PARM_ERROR_CODE")
End Sub

That would be the common code to be added to all DB2Commands for stored
procedures after the "real" function adds the specific parameters. For
example:

Public Function Get_Data1() As DB2Command
Get_Data1 = DB.CreateCommand
Get_Data1.Parameters.Add(GET_DATA1_SPECIFIC_PARM_1 )
Get_Data1.Parameters.Add(GET_DATA1_SPECIFIC_PARM_2 )
Get_Data1.Parameters.Add(GET_DATA1_SPECIFIC_PARM_3 )
Get_Data1.Parameters.Add(GET_DATA1_SPECIFIC_PARM_4 )
Get_Data1.Parameters.Add(GET_DATA1_SPECIFIC_PARM_5 )

Stored_Procedure_Common(Get_Data1)
End Function

Public Function Get_Data2() As DB2Command
Get_Data2 = DB.CreateCommand
Get_Data2.Parameters.Add(GET_DATA1_SPECIFIC_PARM_1 )
Get_Data2.Parameters.Add(GET_DATA2_SPECIFIC_PARM_2 )
Get_Data2.Parameters.Add(GET_DATA2_SPECIFIC_PARM_3 )
Stored_Procedure_Common(Get_Data2)
End Function

The first statement is common to all functions, but is only one
statement. The second (and third and forth, for all parameters the
stored PROCEDURE takes) statment is specific to each function. The
final statement call a common function to execute all that is common to
all of them.

I deally, the code would read

Public Function Get_Data2() As DB2Command
Me. = DB.CreateCommand
Me..Parameters.Add(GET_DATA2_SPECIFIC_PARM_1)
Me..Parameters.Add(GET_DATA2_SPECIFIC_PARM_2)
Me..Parameters.Add(GET_DATA2_SPECIFIC_PARM_3)
Stored_Procedure_Common(Me)
End Function

Or, if some form of inheritance could do it.

I am not sure how many we need to do, but it's probably between two and
three hundred, so common code would help inn writing, manintenance, and
understanding.

B.

Jun 13 '06 #3

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

Similar topics

7
by: vegetax | last post by:
I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj()...
0
by: sector119 | last post by:
I use python 2.4.1 and PIL 1.1.5 and when I execute my program I got error: ../code.py Traceback (most recent call last): File "./code.py", line 7, in ? class DrawPlus(ImageDraw.Draw):...
10
by: Fredrik Tolf | last post by:
If I have a variable which points to a function, can I check if certain argument list matches what the function wants before or when calling it? Currently, I'm trying to catch a TypeError when...
17
by: Eric Brunel | last post by:
Hi all, I just stepped on a thing that I can't explain. Here is some code showing the problem: ----------------------------- class C: f = None def __init__(self): if self.f is not None:
5
by: James Mitchelhill | last post by:
Sorry for the clunky subject line - I have a feeling that not knowing the proper terms for this is part of my problem. I'm trying to write a class that analyses some data. I only want it to do...
9
by: 7stud | last post by:
Hi, I'm trying to figure out what this passage from GvR's tutorial means: ------- Class definitions, like function definitions (def statements) must be executed before they have any effect.......
0
by: mauro | last post by:
Hi all, I am trying to wrap some C code using SWIG (win32, mingw). I am new to SWIG and to the Python/C API so what I am doing is looking at the examples and trying to fit them to my needs, but...
8
by: Viktor | last post by:
Can somebody give me an explanation what happened here (or point me to some docs)? Code: HMMM = None def w(fn): print 'fn:', id(fn) HMMM = fn
32
by: copx | last post by:
Why doesn't the C standard include generic function pointers? I use function pointers a lot and the lack of generic ones is not so cool. There is a common compiler extension (supported by GCC...
7
by: Kurda Yon | last post by:
Hi, I have a class called "vector". And I would like to define a function "dot" which would return a dot product of any two "vectors". I want to call this function as follow: dot(x,y). Well,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
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...
0
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...
0
muto222
php
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.