37

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
2
  • 11
    Jill, why don't you accept Richie's answer ? Commented Dec 11, 2016 at 19:20
  • @Jill448 There's an answer waiting to be accepted. ;) Commented Dec 16, 2022 at 10:18

2 Answers 2

90

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
Sign up to request clarification or add additional context in comments.

2 Comments

Does this mean that the function will stop executing after reaching the first assigning the value to its name? For example: Function getNumber If {condition1} Then getNumber = "423" ElseIf {condition2} Then getNumber = "567" Else getNumber = "890" End Function
@B.Sverediuk No, the function will continue until it reaches either the end of the function or encounters an explicit Exit Function statement.
1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.