By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

Enumerate argument list

P: n/a
Anyone know of a way to enumerate the argument list of a function in
VB.NET.

For example I have a Function add_user (u_id AS INT, u_first_name AS
VARCHAR(50), u_last_name AS VARCHAR(50)).

I want to be able to do something like this:

For each argument in add_user.argumentlist
Select Case argument.name
Case u_id
'Do This
Case u_first_name
'Do this
ETC.
Next argument

Sep 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Looks rather like SQL code than VB.NET code...

Arguments are always there. Why not doing simply :
' Do This for u_id
' Do This for u_first_name
' Do This for u_last_name

Overall I don't really uderstand what you are trying to do...
(you could perhaps add them in an ArrayList or something similar if you
really need to).

--
Patrice

<di**********@gmail.com> a écrit dans le message de
news:11**********************@g43g2000cwa.googlegr oups.com...
Anyone know of a way to enumerate the argument list of a function in
VB.NET.

For example I have a Function add_user (u_id AS INT, u_first_name AS
VARCHAR(50), u_last_name AS VARCHAR(50)).

I want to be able to do something like this:

For each argument in add_user.argumentlist
Select Case argument.name
Case u_id
'Do This
Case u_first_name
'Do this
ETC.
Next argument

Sep 16 '05 #2

P: n/a
Hi,

You can do that, example below:
Private Sub WeirdFunction(ByVal arg1 As Integer, ByVal arg2 As Integer,
ByVal arg3 As Integer)

Dim stFrame As New StackFrame

Dim currentMethod As System.Reflection.MethodBase = stFrame.GetMethod()

Dim currentParameters() As System.Reflection.ParameterInfo =
currentMethod.GetParameters()

For Each param As System.Reflection.ParameterInfo In currentParameters

Select Case param.Name

Case "arg1"

' do whatever

End Select

Next

End Sub

<di**********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Anyone know of a way to enumerate the argument list of a function in
VB.NET.

For example I have a Function add_user (u_id AS INT, u_first_name AS
VARCHAR(50), u_last_name AS VARCHAR(50)).

I want to be able to do something like this:

For each argument in add_user.argumentlist
Select Case argument.name
Case u_id
'Do This
Case u_first_name
'Do this
ETC.
Next argument

Sep 16 '05 #3

P: n/a
Ok I have succesfully gotten my list of paramaters but now I want to
assign values to the paramaters and send the list back to the
funcitons.

Here is what I have now...

Dim typFunction As Type = GetType(SecLink.Db.StoredProcedures)
Dim infoFunction As MethodInfo =
typFunction.GetMethod("spUpdUser_Command")
Dim prmArgument As ParameterInfo
Dim strArgList As String
For Each prmArgument In infoFunction.GetParameters
'Find the correct value from the dataset
If InStr(prmArgument.Name.ToString, "edit_user") > 0 Then
strArgList = strArgList & Session("edit_user")
Else
strArgList = strArgList &
dsUser.Tables(0).Rows(0).Item(prmArgument.Name.ToS tring) & ","
End If
Next

clsDB.StoredProcedures.spUpdUser_Command(strArgLis t)

So I can build a string of values that can be passed back to the
spUpdUser_Command but if I try to pass it just as a string VB.NET does
not like this. It reads strArgList as just being the value for the
first argument the function accepts. I need to find a way to set the
paramaters to a value and then execute the function.

Sep 19 '05 #4

P: n/a
OK this works but now I need to set the paramaters to a value and then
call the funciton with the values I set.

Here is what I have...

Dim typFunction As Type = GetType(Primax.SecLink.Db.StoredProcedures)
Dim infoFunction As MethodInfo =
typFunction.GetMethod("spUpdUser_Command")
Dim prmArgument As ParameterInfo
Dim strArgList As String
For Each prmArgument In infoFunction.GetParameters
'Find the correct value from the dataset
If InStr(prmArgument.Name.ToString, "edit_user") > 0 Then
strArgList = strArgList & Session("edit_user")
Else
strArgList = strArgList &
dsUser.Tables(0).Rows(0).Item(prmArgument.Name.ToS tring) & ","
End If
Next

clsDB.StoredProcedures.spUpdUser_Command(strArgLis t)

When I pass strArgList to my function (spUpdUser_Command) the project
won't compile.

Sep 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.