function(S) in sted of optional

# Thread: function(S) in sted of optional

1. Member
Join Date
Dec 1969
Posts
59

## function(S) in sted of optional

in sted of :<BR><BR>Public function DoIt (byval A as int32,optional byval B as int32 = 24,optional byval C as int32 = 10) as int32<BR> return ((A + B)* C)<BR>End Function<BR><BR>--------------------------------------------------------------<BR><BR>you can have many function :<BR><BR>Public function DoIt (byval A as int32) as int32<BR> return ((A + 24)* 10)<BR>End Function<BR><BR>Public function DoIt (byval A as int32, byval B as int32) as int32<BR> return ((A + B)* 10)<BR>End Function<BR><BR>Public function DoIt (byval A as int32, byval B as int32, byval C as int32) as int32<BR> return ((A + B)* C)<BR>End Function<BR><BR>----------------------------------------------------------------<BR>it is very practicle BUT, if the function has hundreds of lines, how can you avoid to rewrite (or copy-paste ) x time the same function ? how can you use different signatures with only one function ?<BR><BR><BR>thank you

2. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## What you generally do..

.. is have each public function call a common private function.<BR><BR>At least, that&#039;s how I do it.

3. Member
Join Date
Dec 1969
Posts
59

## you mean

...you mean <BR><BR>Public function DoIt (byval A as int32, byval B as int32) as int32 <BR> return (AnotherFunction(A + B)* 10) <BR>End Function <BR><BR>?<BR><BR>not very esthetic but if I don&#039;t find ....thank you !<BR><BR><BR>I was more looking in a direction of delegate or ... ?

4. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## I would do something..

.. like:<BR>Public function DoIt (byval A as int32) as int32<BR>return DoIt(A, 24, 10)<BR>End Function<BR><BR>Public function DoIt (byval A as int32, byval B as int32) as int32<BR>return DoIt(A, B, 10)<BR>End Function<BR><BR>Public function DoIt (byval A as int32, byval B as int32, byval C as int32) as int32<BR>return DoIt((A + B)* C)<BR>End Function

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•