Return more than one value from a function

后端 未结 2 1795
一生所求
一生所求 2021-01-03 10:38

UPDATE: This is the WIP Function.

<%
    Function ReturnTwoValues(Data)

        If Data= Now() Then
            Var1= \"ABC\"
                   


        
相关标签:
2条回答
  • 2021-01-03 10:54

    Pass back an array:

    Function ReturnTwoValues(Date_Field)
        ' Do some date testing using Date_Field and then return the proper values...
        ReturnTwoValues = Array("hello", "world")
    End Function
    
    a = ReturnTwoValues(#7/7/2014#)
    WScript.Echo a(0)    ' ==> "hello"
    WScript.Echo a(1)    ' ==> "world"
    

    Or take advantage of the fact that variables are passed by reference in VBScript:

    Sub ModifyTwoValues(Date_Field, returnOne, returnTwo)
        ' Do some date testing using Date_Field and then return the proper values...
        returnOne = "hello"
        returnTwo = "world"
    End Sub
    
    ModifyTwoValues #7/7/2014#, var1, var2
    WScript.Echo var1    ' ==> "hello"
    WScript.Echo var2    ' ==> "world"
    
    0 讨论(0)
  • 2021-01-03 11:03

    Easy workarounds:

    1. Use an array, or

    2. Use a dictionary object.

    Here's an earlier StackOverflow question that has a full rundown: QTP: How can I return multiple Values from a Function

    0 讨论(0)
提交回复
热议问题