Code: QB64: [Select]
TYPE sub_example_params call_params.x = 10 call_params.y = 20 'each param entry has whatever value was last written to it, hence not necessarily empty, 'to make it happen, you should ivalidate all params at the end of the sub to make them defaults 'for the next call params.x = 5: params.y = 5 params.t = "" 'this would be the defaults for the next call unless they're changed before the next call
Backdraw, you need a lot of individual TYPEs for your individual SUBs/FUNCs...
Is it possible to make one or more parameters at the end of a sub or function optional when calling, and then those would just have default values in the subroutine? For exampleYes can be done but PITA, so most people would say simply "no".
call example(10, 20)
sub example(x, y, text$)
...
end sub
And then in the call, text$ is an empty string?
Is it possible to make one or more parameters at the end of a sub or function optional when calling, and then those would just have default values in the subroutine?
What I do is just write the main function with all the parameters, then define additional versions of the function with a slightly different name and less parameters, which pass whatever default values to the main function. It isn't perfect but it's the simplest approach.
Nice, right that is probably simplest. In old days, when space was so precious you wouldn't think of multiple versions of basically the same function probably be more inclined to add switches to multi-purpose code. But nowadays, space is cheap and coding time and effort the more costly commodity. I like this answer best so far.