Kinook Software Forum

Go Back   Kinook Software Forum > Visual Build Professional > [VBP] General Discussion
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-18-2009, 02:01 PM
digit digit is online now
Registered User
 
Join Date: 05-14-2009
Posts: 14
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.
Reply With Quote
  #2  
Old 06-18-2009, 02:11 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
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
Reply With Quote
  #3  
Old 06-18-2009, 02:26 PM
digit digit is online now
Registered User
 
Join Date: 05-14-2009
Posts: 14
Good idea on MacroOrEmpty. I should have thought of that.

Thanks!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 08:22 PM.


Copyright © 1999-2023 Kinook Software, Inc.