Jill448
Jill448

Reputation: 1793

Return value from a VBScript function

I have two functions, and I am trying to use the result of one function in the second one. It's going to the else part, but it's not printing anything for "cus_number".

How do I get the "cus_number" printed?

Function getNumber
    number = "423"
End Function

cus_number = getNumber

If (IsNull(cus_number)) Then
    WScript.Echo "Number is null"
Else
    WScript.Echo "cus_number : " & cus_number
End If

Upvotes: 37

Views: 157460

Answers (2)

Shubham Verma
Shubham Verma

Reputation: 9971

This is how you can return a value from a function in VBS:

Function shouldSendEmail(Line)
    Dim returnValue
    If Line = False Then
        returnValue = True
    Else
        returnValue = False
    End If
    wscript.echo returnValue
    shouldSendEmail = returnValue
End Function

Call a function:

wscript.echo shouldSendEmail(true)

Upvotes: 1

RichieHindle
RichieHindle

Reputation: 281835

To return a value from a VBScript function, assign the value to the name of the function, like this:

Function getNumber
    getNumber = "423"
End Function

Upvotes: 90

Related Questions