Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing An Array from a Function 1

Status
Not open for further replies.

btalon

Programmer
Dec 16, 2002
144
0
0
US
I'm trying to get the function to pass back an array, but I keep getting errors with this code (Type Mismatch or Subscript Out Of Range). I've tried it several different ways. I know VBScript syntax is a little different, I'm not sure what I'm missing with this. I guess you don't have to set the Function as a Variant with VBScript?

Dim graphicCode(2)

strGraphic = Request.Form("graphic")
graphicCode() = getGraphicCode(strGraphic)

Function getGraphicCode(strGraphic)
Dim graphicCode(2)
Do while x < Len(strGraphic)
if Mid(strGraphic,b,1) = "-" then
graphicCode(1) = Mid(strGraphic,1,b-1)
graphicCode(2)= Mid(strGraphic,b+1,Len(strGraphic))
x = Len(strGraphic) + 1
Else
b = b + 1
End if
x = x + 1
Loop

getGraphicCode = graphicCode()
 
Tip; use the Option Explicit instruction
In your posted code pay attention to the b and x variables.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
>graphicCode() = getGraphicCode(strGraphic)
It will error out whatever way you declare graphicCode. Try instead this for a better chance if the function getGraphiccode return an array of indices (0,1,2).
[tt] graphicCode = getGraphicCode(strGraphic)[/tt]
 
It appears from your post that graphicCode is being declared twice. If you declare it globally, you don't need to pass it to or from a function since you are modifying the global variable.

Try this: remove the declaration from the function and replace:
graphicCode() = getGraphicCode(strGraphic)

with:
for each i in graphicCode
wscript.echo i
next

This should echo out all the entries in graphicCode().
 
If I can be more explicit, it is this.
[tt]
Dim graphicCode [blue]'nothing on the size[/blue]

strGraphic = Request.Form("graphic")
graphicCode = getGraphicCode(strGraphic) [blue]'no (), it's must[/blue]
[green]'... continue with the rest
'... it goes without saying that script is responsible for
'... making the function getGraphicCode(strGraphic) correct
'... otherwise there is no point in discussing passing back an array[/green]
[/tt]
- tsuji
 
Thanks tsuji, your last post did the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top