Question Get parameter values with ScriptControl and ParameterInfo

row118

Member
Joined
Feb 4, 2006
Messages
21
Programming Experience
5-10
:confused: I've almost accomplished getting method parameter name and values.
VB.NET:
TestScripting("I hope this works")
VB.NET:
 Public Sub TestScripting(ByVal A As String)
        Dim oscript As New MSScriptControl.ScriptControl
        oscript.Language = "VBScript"
        For Each oParm As ParameterInfo In MethodBase.GetCurrentMethod.GetParameters
            oscript.AddObject("MyTestStmt", A, True)
            Debug.WriteLine(oscript.Eval("MyTestStmt"))
        Next oParm
    End Sub
here is output as expected:
I hope this works
However, This does not work.
VB.NET:
 For Each oParm ... 
            oscript.AddObject("MyTestStmt", oParm.Name, True)
            Debug.WriteLine(oscript.Eval("MyTestStmt"))
  Next oParm

writes: the variable name.
What am I doing wrong?
I'm using using vb.net 2005 /Vista/Microsoft Script Control 1.0
 
That code is working exactly as it should. In the first code snippet you pass A to AddObject and the contents of A is "I hope this works". In the second code snippet you pass oParm.Name to AddObject and the contents of oParm.Name is "A". The parameter and the name of the parameter are two completely different things. What you're trying to do is like writing Ferrari down on a piece of paper and then expecting to be able to get into it and drive. The name of the object and the object itself are two very different things.

A ParameterInfo only gives you information about the parameter declaration. It doesn't give you the parameter's value. If you're in the method the parameter belongs to then you've got the parameter itself, so why would you need to use reflection? If you're not in the method then the parameter has no value, so getting it would make no sense.
 
Back
Top