Kinook Software Forum

Kinook Software Forum (https://www.kinook.com/Forum/index.php)
-   [VBP] General Discussion (https://www.kinook.com/Forum/forumdisplay.php?f=2)
-   -   subroutine parameters (https://www.kinook.com/Forum/showthread.php?t=4055)

digit 06-18-2009 02:01 PM

subroutine parameters
 
Got a question about optional parameters to subroutines. For a few of my commonly-used subs, I'd like to have some optional parameters to make them a little extensible.

For boolean parameters to say "don't do that" or "do this", probably using a script build condition that checks for the existence of the macro as well as its value can solve that problem. (Though now that I think about it, this kind of behavior is bad programming practice... oops.)

However, for other parameters such as strings to put in the log, things seem a bit more tricky. The best I can come up with is setting the parameter to some default value if the parameter is not defined as the first step of the subroutine. The issue with this is then "popping" that value at the end by deleting the macro.

Is there an example or recommended way of doing this? Or am I trying to do too much? :)

Sorry if this was unclear, and let me know if I can explain anything better.

Thanks in advance.

kinook 06-18-2009 02:11 PM

Create project or global script functions like this (sample is VBScript):
Code:

' return expanded macro value if macro is defined, otherwise
' return an empty string
Function MacroOrEmpty(name)
        Set m = vbld_AllMacros()(name)
        If m Is Nothing Then
                MacroOrEmpty = ""
        Else
                MacroOrEmpty = Application.ExpandMacrosAndScript(m.Value)
        End If
End Function

' return expanded macro value as true/false if macro is defined, otherwise
' return False
Function MacroBool(name)
        Set m = vbld_AllMacros()(name)
        If m Is Nothing Then
                MacroBool = False
        Else
                MacroBool = CBool(Application.ExpandMacrosAndScript(m.Value))
        End If
End Function

' ...

then call from the subroutine as needed:

[MacroOrEmpty("XYZ")]

[MacroBool("ABC")]

...

http://www.kinook.com/VisBuildPro/Ma...ripteditor.htm
http://www.kinook.com/VisBuildPro/Manual/script.htm

digit 06-18-2009 02:26 PM

Good idea on MacroOrEmpty. I should have thought of that.

Thanks!


All times are GMT -5. The time now is 07:48 AM.


Copyright © 1999-2023 Kinook Software, Inc.