Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to Pass Optional Parameters in VBS?
#1
Not Solved Exclamation 
Hi,

We can't use optional parameter in vbs like we can in VB as follow:

Code:
InsertRecord "Read"

Public Function InsertRecord(Optional sLogMsg = "Write")

ValidateRecord(sLogMsg )

End Function

Please provide me an effective solution which will not lead to any major code change!


I am having following option but avoiding because of the "scope" of variable declared for Optional parameter:Sad

Ex.
Code:
mymessage = "OPTIONAL"            'sDelimiter = |
Call ABC("asdf", mymessage)        'sDelimiter = | - DEFAULT
Call ABC("asdf", "12345")        'Override Delimiter = '$'

Public Function ABC(str, mymessage)        ' OptionaL values in function arguments
    If mymessage = "OPTIONAL" Then
        mymessage = "123"
    End If
    Msgbox mymessage
End Function
Reply
#2
Not Solved
Simple, use dictionaries from a string (example not functioning code)

Code:
call X("param1::value1^^param2::value2")

function X(aDict)
dict = call decodeDict(aDict)
  if dict("param1") <> "" then pm1 = dict("param1") else pm1 = ""
OR

make all passable parameters global ( not recomended )

Of cause how you break up the dict and return it I leave to you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pass reference to datatable into function smallsteve 2 2,088 09-28-2017, 09:18 PM
Last Post: smallsteve
  Optional parameter in function amit25007 6 5,428 01-06-2016, 03:29 PM
Last Post: venkatesh9032
  Can you please help me in QTP DP to pass the variable name anshika.agarwal 1 2,754 09-04-2014, 06:43 PM
Last Post: anshika.agarwal
  .vbs script error when trying to insert a value in a sapguitable frebuffi 5 6,859 07-18-2013, 03:04 PM
Last Post: Staff
  optional parameters Ishul 5 8,196 04-03-2012, 11:18 PM
Last Post: supputuri

Forum Jump:


Users browsing this thread: 1 Guest(s)