passing arrays from ASP to a VB function

Kind all,
I have to pass an array from ASP to a VB function..how can I do??
please send some ex. code.
Thanx
jytrAsked:
Who is Participating?
 
BGillhamConnect With a Mentor Commented:
I normally ass a Delimited STRING to the function and then split the string.

MyString = "Var1+Var2+Var3"

Sub MySub(SomeVal)
  Dim MyArray, x
  MyArray = Split(SomeVal,"+")
  For x = LBound(SomeVal) To UBound(SomeVal)
    'Do SOMETHING
  Next
End Sub
0
 
Dave_GreeneCommented:
Being that everything in VBScript is a variant

Create your array like so..

Dim Array1()

Redim Array1(20)

For i = 0 to 20
  Array1(1) = i
Next

Then in the call

Dim objDLL
set ObjDll = Create.ServerObject("DLLNAME.DLL", "OPT Server")

RetVal = ObjDLL.FunctionName(Array1)
0
 
Dave_GreeneCommented:
Sorry.. typeo

Server.CreateObject
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Dave_GreeneCommented:
As for the function recieving the array

Simple define the array as a variant

Public Function InArray(ArrInput as variant) as boolean
   for i = 0 to Ubound(ArrInput)
   'if it is a large array make sure you capture the Ubound value to a variable and use it instead, for performance.
   Next i
End Function
0
 
jytrAuthor Commented:
and in the VB code the arrays how is passed to the function??
0
 
jytrAuthor Commented:
ah..ok
0
 
jytrAuthor Commented:
Im am trying it :-)
0
 
Dave_GreeneCommented:
Here is some more information if you need it

http://www.15seconds.com/issue/990826.htm
0
 
PaulHewsCommented:
>>'if it is a large array make sure you capture the Ubound value to a variable and use it instead,
for performance.

Not needed Dave, For ... Next will only call Ubound once.
0
 
Dave_GreeneCommented:
Forgot one thing... passing the array ByVal instead of the default ByRef

<<Change>>
Public Function InArray(ByVal ArrInput as variant) as boolean
0
 
Dave_GreeneCommented:
Paul are you certain?  Is it only with Do Loops then?
0
 
jytrAuthor Commented:
I continue receiving subscript out of range...any ideas?
0
 
Dave_GreeneCommented:
It is all untested, I typed it from memory.'

Try this

For i = 0 to 19  in the asp page
0
 
Dave_GreeneCommented:
Paul, After thinking about it, it does make sense...  And yes, I think it would apply to Do Loops only...  Let me know if you know otherwise  :)

Thanks Again Paul!
0
 
PaulHewsCommented:
>And yes, I think it would apply to Do Loops only...
 Let me know if you know otherwise  :)

In a Do ... Loop the expression is fully evaluated every time.  In a For ... Next, the beginning and end points are only evaluated once.  It's easy to test:

Private Sub Command1_Click()
    Dim i As Integer
    Dim strMyArray(1 To 10) As String
    Dim x As Integer
    x = 100
    For i = 1 To x
        x = x - 1
        Debug.Print i
    Next i
End Sub

0
 
Dave_GreeneCommented:
Very Nice Paul!  Thanks!  Have a great weekend!
0
 
PaulHewsCommented:
Try this instead:

Dim Array1

Redim Array1(20)
0
 
Dave_GreeneCommented:
Paul, that is the exact code I have in my first post..  Just an FYI

jytr, How are we coming on this?  Did you get it to work?
0
 
PaulHewsCommented:
Except that you declared it as an array of variants, and I declared it as a variant.  Not sure if that is causing the problem, but it would be nice to rule it out.
0
 
Dave_GreeneCommented:
Oh yea...  Now I see it... looked at it 3 times and didn't notice that  :)  Time to go home  :)
0
 
aminerdCommented:
Public Sub Something(Array As Variant)
0
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.

All Courses

From novice to tech pro — start learning today.