Wish CallSub - free number of parameters

LucaMs

Expert
Licensed User
Longtime User
Currently you can pass a maximum of two parameters, using CallSub3 (or CallSubDelayed3).
The ideal would be that you could pass any number of parameters (also that you could declare them as optional in the routine signature, but this is another question).

I know, I can pass a data structure (Array, List,... and custom types) but using directly N parameters you could see the variable names you are "sending".

---

[Of course, I do not need this urgently, since it is possible to get around this by just using data structures. Also, I do not know if I can buy the upgrade license, soon... Probably I will not have enough money to buy some sandwiches and the upgrade license too :D:(; but... if I do not bother Anywhere Software... who does it? Someone must do this dirty work! :p]
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Use an array or a map. It is very simple.
I know, I can pass a data structure (Array, List,...

B4X:
' mmm what number and type variables should I pass to this strange routine?
Sub DoSomething(Data() As Object)
'...
End Sub


' ok I have to pass: ...
Sub DoSomething(Name As String, Age As Int, Address As String, State As clsEmplyeeState)
'...
End Sub

B4X:
' Direct call
DoSomething( <--- here you can see the required parameters, comma after comma


CallSub(X, "DoSomething", arrData) ' ???

CallSub(X, "DoSomething", NameX, AgeX, AddressX, EmployeeStateX)


I know you know this, but if you answer to use an array or a map...
 

alwaysbusy

Expert
Licensed User
Longtime User
But when you read a call like the second in the example...
How about using something like this:

CallSub2(X, "DoSomething", Array As Object(NameX, AgeX, AddressX, EmployeeStateX))

Or:

CallSub2(X, "DoSomething", CreateMap("Name": NameX, "AgeX": Age, "Address" :AddressX, "EmployeeState": EmployeeStateX))
 

LucaMs

Expert
Licensed User
Longtime User
How about using something like this:

CallSub2(X, "DoSomething", Array As Object(NameX, AgeX, AddressX, EmployeeStateX))

Or:

CallSub2(X, "DoSomething", CreateMap("Name": NameX, "AgeX": Age, "Address" :AddressX, "EmployeeState": EmployeeStateX))
This is probably the best alternative.

Having the possibility of using an indeterminate number of parameters, the advantages I have described previously remain, however.
 

LucaMs

Expert
Licensed User
Longtime User
How about using something like this:

CallSub2(X, "DoSomething", Array As Object(NameX, AgeX, AddressX, EmployeeStateX))

Or:

CallSub2(X, "DoSomething", CreateMap("Name": NameX, "AgeX": Age, "Address" :AddressX, "EmployeeState": EmployeeStateX))
Note that you would then be forced to write the routine this way:

Sub DoSomething(Data As Map)

(or Sub DoSomething(Data() As Object)

not very understandable.
 

rraswisak

Active Member
Licensed User
Longtime User
I will passed/use variable with Type data-type for this

B4X:
Type tEmployee (Name As String, Age As Int, Address As String , EmployeeState As String)
Dim employee As tEmployee

employee.Name = "aaa"
employee.Age = 17
employee.Address = "bbb"
employee.EmplyeeState = "ccc"

CallSub2(X, "SomeSub", employee)
 
Top