Micro Focus QTP (UFT) Forums
how to Pass Optional Parameters in VBS? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: how to Pass Optional Parameters in VBS? (/Thread-how-to-Pass-Optional-Parameters-in-VBS)



how to Pass Optional Parameters in VBS? - ShrikantBiradar3449 - 04-06-2011

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



RE: how to Pass Optional Parameters in VBS? - Skepsis - 06-13-2011

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