Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optional parameter in function
#1
Not Solved
Hello

I am unable to put optional parameter in function.
below is an example

Code:
Public Function fun(var1, var2, var3, var4)
    Script
End Function

I don't want to enter value to var4 every time I use function. I want var4 to be optional.


Regards
Amit
Reply
#2
Not Solved
I think this is not possible. I would suggest Make two functions with 3 and 4 parameters and write it like this in script.
Code:
If Condition

Call Fn1(Var1, Var2, Var3)

Else

Call Fn2(Var1,Var2,Var3,Var4)
Reply
#3
Not Solved
But with this method, i still don't have choice with Var4. The case is i will enter value of Var4 only in some specific cases, not always.
Reply
#4
Not Solved
Another way, using Null or Empty argument:
Code:
Function myfunc(arg1,arg2,arg3,arg4)
If IsNull(arg1) OR IsEmpty(arg1)
      'ignore arg1
Else
      'use arg1
End If
If IsNull(arg2) OR IsEmpty(arg2)
      'ignore arg1
Else
      'use arg1
End If
.....
'Your code is here

End Function

To call your function:
Code:
Dim a
a = myfunc(NULL,arg2,,arg4)
Reply
#5
Not Solved
You can also use dynamic parameters using dictionary object/array.
Reply
#6
Not Solved
Use switch case method to call the different variables in different cases
Reply
#7
Not Solved
If u dont want to pass the value in the argument u can leave empty instead of removing parameter.

Please find the snippet:


Code:
Fun Abc(Par1,Par2,Par3,Par4)

---
--
End Function

Call Abc("1","",2","3")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Is there a way to create dynamic objects by declaring the type of object as parameter lotos 3 2,212 11-08-2017, 11:15 PM
Last Post: lotos
  Calling a Function in Function Library when function is defined in an Action jitenderkkr 0 2,984 11-27-2014, 12:53 PM
Last Post: jitenderkkr
  impossible to pass a parameter of type 64 bytes in a webservices dosreis 0 2,177 06-21-2013, 01:55 AM
Last Post: dosreis
  Test Parameter hadar 0 1,860 02-11-2013, 01:27 AM
Last Post: hadar
  optional parameters Ishul 5 8,208 04-03-2012, 11:18 PM
Last Post: supputuri

Forum Jump:


Users browsing this thread: 1 Guest(s)