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.