How to Return more than one value from a VBScript Function

How do you return additional return values for a VBScript function besides the value that is returned by setting the function name to the return value?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dba123Author Commented:
I don't think you understand.  I want to take this function and return not only StatusColor but an additional variable in my Case statment that I could grab after the function has been called:

      Dim totalused, status, totalspace

      strSQL3 = "sp_Get_DiskSpaceUsed @ResourceID=" & ResourceID
      Set Query3 = objConnection.Execute(strSQL3)

      status = "open"
      totalused = 0

      If Not Query3.EOF Then
            totalspace = Query3("totalspace")
            totalspace = 0
      End If

      Set Query3 = Query3.NextRecordSet

      '### get total space used by all users for this resource and set flag
            If NOT Query3.EOF Then
                  Do While NOT Query3.EOF
                        totalused = totalused + Query3("spaceused")
            End If

            Set Query3 = Nothing

      '### Check space left; Leave 10 gigs free or else full
            If totalused > totalspace - 11 Then
                  status = "full"
            End If

      '### Check to see if I'm using this resource and set flag if so
            strSQL3 = "sp_Check_DoIUseThisResource @CheckedOutByID=" & EmployeeID & ", @ResourceID=" & ResourceID
            Set Query3 = objConnection.Execute(strSQL3)
            If Not Query3.EOF Then
                  status = "me"
            End If

            set Query3 = Nothing

            Select Case status
                  Case "open"
                        StatusColor = "<img src=""images/gr.gif"" border=""0"">"
                  Case "full"
                        StatusColor = "<img src=""images/rd.gif"" border=""0"">"
                  Case "me"
                        StatusColor = "<img src=""images/bl.gif"" border=""0"">"
            End Select

End Function
try returning an array

this will help to know more
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

dba123Author Commented:
so basically what you are saying is that I'd do something like this:

Function FunctionName(parameter1,....)

Dim temparray()

<code to fill in array with values>

FunctionName = temparray()

End Function

Then I'd access those values just like FunctionName is an array doing something like FunctinName(2) ?
probably easier to declare two global variables and set them in the function
another way is to pass one parameter byref and then use that var to return a value:

Function GetRGB(ByVal hex, ByRef red, ByRef green, ByRef blue)

  If Not IsNumeric(hex) Then
    red = 0
    Greeen = 0
    blue = 0
    Exit Function
  End If

  ' ... extract red green and blue values here and place them in the right vars
End Function

Dim red, green, blue

Call GetRGB( 1234567, red, green, blue)

Response.Write "Red value: " & red & "; Green value: " & green & "; Blue value: " blue & ";"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
One other option is to create your own object and then use the function to set your properties.

dba123Author Commented:
so you don't have to set the function's name to the output value?  You can setup variables and then access them from any function like this?
dba123Author Commented:
>> ' ... extract red green and blue values here and place them in the right vars

can you elaborate?
Here is what I had in mind:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<title> New Document </title>
<script language="VBScript">
Class objSpace
            Public SpaceAvailable
            Public SpaceUsed
            Public ObjectStatus
End Class

Dim objDBA123
sub showMe()
      Set objDBA123 = New objSpace
      objDBA123.SpaceAvailable = 100
      objDBA123.SpaceUsed = 50
      objDBA123.ObjectStatus = "The Status is fine!"
end sub

sub displayValues
      call showMe()
      msgbox objDBA123.SpaceUsed
      msgbox objDBA123.SpaceAvailable
      msgbox objDBA123.ObjectStatus
end sub


<body onLoad=displayValues>
ok, in vbscript you can pass a variable to a function (or sub) one of two ways: byref and byval.  Byval copies the value of the variable to a new variable when calling the function, so that any modification of the variable inside the function does not modify the original value.  ByRef, on the other hand, passes a reference to the original variable to the function so that when you edit it inside the function you are editing the origninal variable and not just a copy of its value.  You could  still return a value from a function just as you always have before in addition to passing variables byref and using them as return variables.

As for the "function" that I made up... I did just that... I didn't actually spend the time to make the function.  Basically though, the intention of the function was to extract color values from a six character hex string commonly used in html to represent colors, like "#FFFFFF" for white, "#000000" for black, and everything in between.  To complete this function you would have to separate the characters into three groups: "FF-FF-FF" -- representing "Red-Green-Blue" respectively.  Then convert each of these values into numeric format and store them in the appropriate variables.  This function does all that:

Function GetRGB(ByVal strHex, ByRef red, ByRef green, ByRef blue)
      If Left(strHex, 1) = "#" Then
            strHex = Right(strHex, Len(strHex)-1)
      End If
      If Len(strHex) <> 6 Then
            red = 0
            green = 0
            blue = 0
            GetRGB = False
            Exit Function
            red = CInt("&H" & Left(strHex, 2))
            green = CInt("&H" & Mid(strHex, 3, 2))
            blue = CInt("&H" & Right(strHex, 2))
            GetRGB = True
            Exit Function
      End If

End Function

Dim test, red, green, blue
test = "#ffc0c0"
If GetRGB(test, red, green, blue) Then
      Response.Write(test & " is a valid color comprised of Red: " & Red & " Green: " & green & " Blue: " & blue)
      Response.Write(test & " is not a valid color")
End If
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.