ASP VBScript Subroutine Multiple Return Values

Posted on 2006-06-11
Last Modified: 2012-06-27
Hi friends,

Can subroutines return multiple values? If so how?

And will these return values have to be returned as an array? And again, how?

Thanks :-)

Question by:LeeGolding
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 14

Accepted Solution

huji earned 250 total points
ID: 16881795
Hi again!
The easiest way to return more than one value from a FUNCTION is to use an array output:

FUNCTION returnTwoAndFour(arg)
  Dim temp(2)
  temp(0) = arg
  temp(1) = "Four"
  returnTwoAndFour = temp

Dim test(2)

Response.Write returnTwoandFour("Two")(1)
Response.Write "<BR>"
Response.Write returnTwoandFour("Two")(0)

Author Comment

ID: 16881813
Hi again :-)

What about from a Sub?

LVL 14

Expert Comment

ID: 16881827
Well, SUBs are not created to return values. The can modifed the variables defined outside them (let's call them global variables) but they can not return values directly. Functions are used for that.
You may declare a variable outside your SUB, of array type and enough size. Then you may fill it inside your SUB.
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

LVL 14

Expert Comment

ID: 16881832
Like this for example:

  Option Explicit
  Dim Y(2)


  Response.Write Y(1)

Sub SetLocalVariable
    Y(1) = "Some text"
End Sub

Author Comment

ID: 16881851
Thanks for clearing that up :-)

LVL 14

Expert Comment

ID: 16881860
You are very welcome. :)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question