You cannot pass a subroutine name as a variable in B4R, because the compiler converts all non-constant strings to fixed values at compile time.
More importantly, B4R does not allow dynamically calling a subroutine by its name.
CallSubPlus(SubName as SubVoidByte, MsDelay as ULong, Tag as Byte)
Here, "SubName" is not a string, but a function pointer generated by the compiler.
Therefore, you must pass the sub's name directly, never a variable.
In B4R, strings are not dynamic; they become constants in ROM. There is no reflection mechanism like in B4A/B4J.
The compiler must know at compile time which function will be called.
You can create an array of function pointers and select one of them via an index.
Sub Process_Globals
Public Sub1 As SubVoidByte
Public Sub2 As SubVoidByte
Public FuncTable(2) As SubVoidByte
End Sub
Sub AppStart
FuncTable(0) = Sub1
FuncTable(1) = Sub2
Dim idx As Byte = 1
CallSubPlus(FuncTable(idx), 1000, 0)
End Sub
Sub Sub1(Tag As Byte)
Log("Sub1 exécutée")
End Sub
Sub Sub2(Tag As Byte)
Log("Sub2 exécutée")
End Sub
Here, you pass an index, not a name.
You can use a Select Case in a generic sub. You always call the same sub, and you decide what to do based on an identifier.
CallSubPlus(Dispatcher, 1000, 2)
Sub Dispatcher(Tag As Byte)
Select Tag
Case 1
Action1
Case 2
Action2
End Select
End Sub
Alternatively, use a custom type containing a function pointer. B4R allows you to store a SubVoidByte in a type.
Type Task(SubPtr As SubVoidByte, Delay As Long, Tag As Byte)
Dim t As Task
t.SubPtr = Action1
t.Delay = 500
t.Tag = 7
CallSubPlus(t.SubPtr, t.Delay, t.Tag)
In conclusion, you cannot pass a subname as a string.
You must pass a function pointer, which is known at compile time.
If I'm wrong, please tell me.