Hello, I am looking to pass the name of a the Sub statement, "Test2" to a Sub rule "Test" in the code below. However, I receive an error that otest () in Sub Test is not a method. Is this possible? If so could someone identify what I am missing? Thanks in advance.
Sub Main otest = "Test2" Test(otest) End Sub Sub Test (otest) otest () End Sub Sub Test2 () MessageBox.Show("Message", "Title") End Sub
If I understand correctly on what you are trying to do, this should do what you want or point you in the right direction. Hope this helps.
Dan V
Sub Main otest = "Test2" Test(otest) End Sub Sub Test(ByVal PassedInValue As String) MessageBox.Show(PassedInValue) End Sub
Thank you for the reply. It worked for passing the argument to the message box , however I was looking to to see if the name of a Sub or Function can be passed from another Sub or Function.
As shown it looks strange, but this is just a simple test for a code that is looping through the parts in an assembly for replacement that has several sets of variables that provide several scenarios for a single function. Below I added more description on how it should function:
Sub Main oTest = "Test2"
'specifies the name of the rule I am going to call in Sub Test, "Test2"
Test(oTest)
'passes oTest value to Sub Test End Sub Sub Test (oTest) oTest ()
'Calls Sub Test2 to run End Sub Sub Test2 () MessageBox.Show("message", "Title")
'provides a message so that I can verify this method works End Sub
I understand now. I don't believe you can use a named argument as the function/method to call. In my years of development, I've never run across doing something like this where you want to take an argument and directly pass it as the function/method name. I would put in an if statement to check the value of the argument and then call the proper function/method.
With ilogic, if the Test2 sub can be another rule instead of a sub within the rule then you can use the iLogicVB.RunRule(PassedInValue).
DanV
Sub Main otest = "Test2" Test(otest) End Sub Sub Test(ByVal PassedInValue As String) If PassedInValue = "Test2" Then Call Test2 End Sub Sub Test2() MessageBox.Show("test") End Sub
You can actually. It requires a level of coding that is 'one up' from iLogic, in the .Net environment in the type namespace. VB.Net can run in the iLogic editor.
How deep down the rabbit hole do you wish to go?
I don't want to go too deep into the rabbit hole. For what he wanted, there's other ways to do it.
hummm....I've only used InvokeMember with mouse or keyboard actions. But will have to look into it. Thanks!
Thank you all for the help. I think I am over complicating it, so I will move on to the next solution (no need to chase the rabbit).
You can do it with an Action delegate. This is simpler to use than Invoke. It doesn't use text strings for the Sub names, which could be a disadvantage. However, you can assign delegates to variables. Here's a sample.
Sub Main Test(AddressOf Test1) Dim delegate2 As Action = AddressOf Test2 Test(delegate2) End Sub Sub Test (oTest As Action) oTest () End Sub Sub Test1 () MessageBox.Show("Test1", "Title") End Sub Sub Test2 () MessageBox.Show("Test2", "Title") End Sub
Can't find what you're looking for? Ask the community or share your knowledge.