This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- How can i Pass an optional parameter to a subroutine
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 13, 2011
09:49 AM
How can i Pass an optional parameter to a subroutine
Hi,
I Want to write a function that can received different number of parameters, f.e:
How can i write it?
Thanks
I Want to write a function that can received different number of parameters, f.e:
prototype trace(HWND, STRING,NUMBER);
function trace(hMSI, message, flag)
begin
end;
trace(hMSI,"test",1);
trace(hMSI,"test");
function trace(hMSI, message, flag)
begin
if (flag = 1) then
else
endif;
MessageBox(message,INFORMATION);
else
MessageBox("111111" + message,INFORMATION);
endif;
end;
trace(hMSI,"test",1);
trace(hMSI,"test");
How can i write it?
Thanks
(5) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 13, 2011
02:51 PM
I am not sure what you are asking. But is this what your looking for?
prototype trace(HWND, STRING,STRING);
function trace(hMSI, AddStr, message)
STRING svNewStr;
begin
if (StrLength(AddStr) > 0 ) then
svNewStr = AddStr + message;
else
svNewStr = message;
endif;
MessageBox(svNewStr,INFORMATION);
end;
trace(hMSI,"1111111","test");
trace(hMSI,"", "test");
prototype trace(HWND, STRING,STRING);
function trace(hMSI, AddStr, message)
STRING svNewStr;
begin
if (StrLength(AddStr) > 0 ) then
svNewStr = AddStr + message;
else
svNewStr = message;
endif;
MessageBox(svNewStr,INFORMATION);
end;
trace(hMSI,"1111111","test");
trace(hMSI,"", "test");
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 14, 2011
01:17 AM
Yes and no 🙂
I want/need that the second parameter will be optional - Can i call to function like this: trace(hMSI,"test");
or if the second parameter is empty i must to call like this: trace(hMSI,"test","");
the function always get Address and the message is optional.
Thanks.
I want/need that the second parameter will be optional - Can i call to function like this: trace(hMSI,"test");
or if the second parameter is empty i must to call like this: trace(hMSI,"test","");
the function always get Address and the message is optional.
Thanks.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 14, 2011
07:28 AM
You will have to call the function with the empty string. I do not think you can create a function that takes optional input. You can in C or C++. The only function in installscript that works that way is Sprinft or SprintfBox.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 18, 2011
08:48 AM
So if you can send empty value to Sprinft and SprintfBox functions - you can do it to your private functions as well, no?
I want to know if the following 2 marked options can be used:
I want to know if the following 2 marked options can be used:
prototype trace(HWND, STRING,STRING);
function trace(hMSI, message, AddStr)
begin
if (StrLength(AddStr) > 0 ) then
else
endif;
end;
trace(hMSI,"test","111111");
trace(hMSI,"test");
function trace(hMSI, message, AddStr)
STRING svNewStr;
begin
if (StrLength(AddStr) > 0 ) then
svNewStr = AddStr + message;
else
svNewStr = message;
endif;
MessageBox(svNewStr,INFORMATION);
end;
trace(hMSI,"test","111111");
trace(hMSI,"test");
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Dec 21, 2011
06:31 PM
I think you can have variable arguments by including ... in a function prototype, and then referring to whatever matches the ... as an array of VARIANT-type items. That's apparently what the Sprintf[Box|MsiLog] and AskOptions functions do. This isn't the same as optional arguments, of course, and so you might be better off creating different functions, or passing null arguments when not needed as suggested.