View Full Version : Passing Array Names to ASP Functions
oracleguy
09-15-2002, 06:50 PM
Lately I've been exploring some new territory with this website (as far as ASP goes) I'm building. And its gonna be all pretty nifty when I'm done. But I've ran into another problem.
I have this function:
Function LoadSystemPrice(SystemName, ArrayName)
rsDC.Close
cmdDC.CommandText="SELECT * From " & SystemName & " WHERE (PartType);"
rsDC.Open cmdDC, , 0, 1
rsDC.MoveFirst
Do while not rsDC.EOF
If rsDC.Fields(1).Value="[PLACE]" then
rsDC.MoveNext
exit do
End If
rsDC.MoveNext
Loop
For x=1 to 3
If rsDC.EOF then exit for
ArrayName(x)=rsDC.Fields(1).Value
rsDC.MoveNext
Next
End Function
And what I need to do is call the function like:
Dim Vel1(3)
LoadSystemPrice "Velocity", Vel1
But I get this error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'ArrayName'
/opcv6/wizard4.asp, line 113
Line 113 is the red line. My question is, if possible how do I pass an array's name to a function?
dfrancis
09-15-2002, 08:26 PM
Line 113 is the red line. My question is, if possible how do I pass an array's name to a function? [/B]
I am a bit out of my comfort array... I mean area here. But first glance begs the question... where did you define your array?
Dim ArrayName()
?
DIM is your access key to passing variables, and in that I can see where you did... I guess it just jumped out at me.
dfrancis
oracleguy
09-15-2002, 10:09 PM
I shouldn't have to define ArrayName because it is in the Function declariation... right? :confused:
dfrancis
09-15-2002, 10:45 PM
I shouldn't have to define ArrayName because it is in the Function declariation... right?
Sounds logical... but this is MS ya know. I think an array always has to be dimmed and even redimmed. I looked at few I have here and they are defined inside the function. 4guys has some good examples.
To me this means write your process normally then add function at the top and bottom to "contain" it.
If I run across a good example... I will try to remember to post it here. Sorry :rolleyes:
Roy Sinclair
09-16-2002, 07:36 PM
The problem is that you used function when you should have used sub. A function is expected to return values while a sub does not and in your case you aren't returning a value, you're altering a passed value.
oracleguy
09-17-2002, 10:00 PM
Originally posted by Roy Sinclair
The problem is that you used function when you should have used sub. A function is expected to return values while a sub does not and in your case you aren't returning a value, you're altering a passed value.
I tried that and that didn't solve it.
glenngv
09-18-2002, 03:13 AM
i made a simple sub with an array as the parameter, and it works just fine.
in the line:
ArrayName(x)=rsDC.Fields(1).Value
what data type of the field in the db?
just a reminder:
arrays in vbscripts start at index 0 not 1.
and when you declare
dim ArrayName(3)
it means the last index of the array is 3, therefore the length of the array is 4 which means the indexes are: 0,1,2,3.
for quick reference, visit http://www.devguru.com/Technologies/vbscript/quickref/array.html
dfrancis
09-18-2002, 04:43 PM
Checks the array mside a function... maybe this will help.
Function InA(strV)
Dim v
For v = 0 to UBound([arrayname])
If selCriteria(v,1) = cstr(strV) Then
InA = TRUE
Exit Function
End If
Next
InA = FALSE
End Function
oracleguy
09-21-2002, 04:54 AM
That appears to have solved it! :)
:thumbsup: Thanks for everyones help.
whammy
09-21-2002, 05:05 PM
Dang. That crossed my mind, too - but I didn't think that was the problem. Sorry.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.