I'm not very good with iLogic so please bear with me. I am trying to figure out how to pass information between two separate private subs contained within the same Rule. I think I understand how to get info from the first sub to the second but I don't know how to pass info back. Can anyone explain this to me?
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Subs, as you will find in any programming that use them, are there because they are NOT supposed to return a value. It's not their intent. They are supposed to be there to perform a task based upon the given inputs.
If you want to return a value, you need to use a Function. Which has all the same functionality of a sub, but can return a value.
HOWEVER, you can declare variables as shared/global so that a Sub can act on them... however, this can make it hard to follow the data around when it comes to debugging.
Example:
Sub Main Dim x As Integer = 5 Dim y As Integer = 2 Call MathSub(x,y) FunctionResult = MathFunction(x,y) MsgBox("This is in main sub. The result of the function call is: " & FunctionResult) End Sub 'note the sub does not have a type Sub MathSub(var1 as Integer, var2 as Integer) Dim resultvar As Integer resultvar = var1 + var2 MsgBox("I am in the sub MathSub. The result I give is: " & resultvar) End Sub 'note the function has to have a type Function MathFunction(var1 as Integer, var2 as Integer) As Integer Dim result As Integer result = var1-var2 Return result End Function
Example using global variables:
See: for more info on access modifiers:
https://msdn.microsoft.com/en-us/library/76453kax.aspx
'Need to put all of the rule inside of a class in order to be able to use the shared variable. Class TestShared 'This shared access modifier keyword makes the information accessible to all subs/functions/properties in this class Shared oResult As Integer Sub Main oResult = 0 Dim x As Integer = 5 Dim y As Integer = 2 MsgBox("Before sub call result: " & vbLf & oResult) PerformMath(x, y) MsgBox("After sub call result: " & vbLf & oResult) End Sub 'note the sub does not have a type Sub PerformMath(var1 as Integer, var2 as Integer) oResult = var1 + var2 End Sub End Class
Thanks for the help. I'm going to try applying what you've shown me when I'm back in the office tomorrow. Hopefully I can make it work!
Didn't get around to working on the iLogic code until today. I was able to get things working using your example as a guide. Thank you for the help!
Can't find what you're looking for? Ask the community or share your knowledge.