0

I have a question regarding how can i use a method name configurable to be called. E.g

1.I have a xml file with three elements looking like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<root>
    <element attribute1="a" attribute2="b" attribute3="Send" />
</root>

2.I am using a List (i made a class with three elements and create an object type list of that class) to store the elements from the xml file.

3.Then using a For statement : For Each element As ClassList In GetList i want to call the configurable method from the xml file instead :

Theoratically instead of SendWait i want to have the value of attribute3(the value is SendWait) to be called.

instead of SendKeys.SendWait("{ENTER}") something like this:

SendKeys.element.Thirdelement()("{ENTER}")
  • the value of element.Thirdelement() is SendWait

I know that attribute3 could have 2 values : Send or Sendwait Should i use a if statement, or is there any solution available?

If element.ThirdElement() = "SendWait" Then
                                SendKeys.SendWait("{ENTER}")
                            Else
                                SendKeys.Send("{ENTER}")

I am new in programming so please excuse me if one of the statement above is an aberration!

LE: I have a new class ListClass1 with three members and properties:

firstElement()
secondElement()
thirdElement()

I am using this class in order to store the data from xml file

<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<element attribute1="a" attribute2="b" attribute3="Send" />
</root>

So after i add the values to the list, for example : element.ThirdElement() will have the value from attribute3 ("Send"). Also element.secondElement() will retain the value from attribute2 and so on.

Operagust
  • 137
  • 5
  • 6
  • 16

1 Answers1

0

You can use reflection to do the task. First Define a class holding your methods:

Public Class MethodsToExecute
    Public Sub Send(par1)
       SendKeys.Send("{ENTER}") 
    End Sub
    Public Sub SendWait(par1)
       SendKeys.SendWait("{ENTER}")
    End Sub
End Class

Then create a Sub for handling:

Public Shared Sub ExecuteMethodByName(ObjectToInvoke As Object, MethodName As String, ParamArray Parameters() As Object) 
     Dim m As Reflection.MethodInfo = ObjectToInvoke.GetType.GetMethod(MethodName)
     m.Invoke(ObjectToInvoke, Parameters)
End Sub

and now execution

dim mte as new MethodsToExecute

iterate thorough xml file and do

 ExecuteMethodByName(mte,element.ThirdElement(), element.firsElement(),element.secondElement())

The problem is that solution is dependent on attribute order not by their names but with more extensive reflection usage you can handle it too. ParamArray Example

Is it understandable?

IvanH
  • 5,039
  • 14
  • 60
  • 81
  • thanks for your answer but honestly i don't understand how to implement that in my case...i have this phrase = SendKeys.SendWait("{ENTER}" and need to have SendKeys.element.Thirdelement()("{ENTER}") – Operagust Apr 12 '12 at 07:24
  • I have made some edit. But I probably don't understand your code. What is ThirdElement? Can you add a bit more code? – IvanH Apr 12 '12 at 10:19
  • I hope I am using elements corectly. I suppose that they contain attributes values). – IvanH Apr 12 '12 at 12:07