L
Les Hughes
Short Answer: No
Use the if or select statements
Use the if or select statements

someMethodDelegate = AddressOf A
Assuming that the signatures of the methods are the same, you can use a
delegate to do so...
Dim someMethodDelegate(SomeSortOfString As String) As [Delegate]
someMethodDelegate = AddressOf A
someMethodDelegate(SomeSortOfString)
...
Sub A(SomeString As String)
...
End Sub
Sub B(SomeString As String)
...
End Sub
HTH
David Williams [VB.NET MVP]
Rico Rivera said:I want to call a method dynamically based on a string
For example
When s = "A" Then method A would get called. I don't wan't to use a
bunch of "If" statements.
Something like:
someMethod = AddressOf s 's = A
someMethod(SomeSortOfString)
Sub A(ByRef SomeString As String)
...
End Sub
Sub B(ByRef SomeString As String)
...
End Sub
Is this possible?
I want to call a method dynamically based on a string
Cor Ligthert said:Hi David,
And than build a complete program around it to prevent runtime errors?
Sometimes technical methods are simple however if it is a solutions is
often
the question.
Just my thought.
Cor
Assuming that the signatures of the methods are the same, you can use
a
delegate to do so...
Dim someMethodDelegate(SomeSortOfString As String) As [Delegate]
someMethodDelegate = AddressOf A
someMethodDelegate(SomeSortOfString)
...
Sub A(SomeString As String)
...
End Sub
Sub B(SomeString As String)
...
End Sub
Rico Rivera said:Hi David,
Yes, that is what I am looking for... one question. When you had:
someMethodDelegate = AddressOf A
Method 'A' is hard coded... I needed something like
someMethodDelegate = AddressOf s
s is a String that could have A or B or C (which are methods). In
other words I don't know what method to call until runtime and based
on the string, then the method would get called. All signatures will
be the same.
Thanks
Rico
Assuming that the signatures of the methods are the same, you can use a
delegate to do so...
Dim someMethodDelegate(SomeSortOfString As String) As [Delegate]
someMethodDelegate = AddressOf A
someMethodDelegate(SomeSortOfString)
...
Sub A(SomeString As String)
...
End Sub
Sub B(SomeString As String)
...
End Sub
HTH
David Williams [VB.NET MVP]
Rico Rivera said:I want to call a method dynamically based on a string
For example
When s = "A" Then method A would get called. I don't wan't to use a
bunch of "If" statements.
Something like:
someMethod = AddressOf s 's = A
someMethod(SomeSortOfString)
Sub A(ByRef SomeString As String)
...
End Sub
Sub B(ByRef SomeString As String)
...
End Sub
Is this possible?