Solved

passing arrays from ASP to a VB function

Posted on 2001-07-27
21
208 Views
Last Modified: 2012-08-14
Kind all,
I have to pass an array from ASP to a VB function..how can I do??
please send some ex. code.
Thanx
0
Comment
Question by:jytr
  • 11
  • 4
  • 4
  • +2
21 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327602
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
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327607
Sorry.. typeo

Server.CreateObject
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327666
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
 

Author Comment

by:jytr
ID: 6327682
and in the VB code the arrays how is passed to the function??
0
 

Author Comment

by:jytr
ID: 6327685
ah..ok
0
 

Author Comment

by:jytr
ID: 6327689
Im am trying it :-)
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327759
Here is some more information if you need it

http://www.15seconds.com/issue/990826.htm
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6327770
>>'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
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327771
Forgot one thing... passing the array ByVal instead of the default ByRef

<<Change>>
Public Function InArray(ByVal ArrInput as variant) as boolean
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327774
Paul are you certain?  Is it only with Do Loops then?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jytr
ID: 6327782
I continue receiving subscript out of range...any ideas?
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327805
It is all untested, I typed it from memory.'

Try this

For i = 0 to 19  in the asp page
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327810
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
 
LVL 38

Expert Comment

by:PaulHews
ID: 6327872
>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
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327878
Very Nice Paul!  Thanks!  Have a great weekend!
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6327881
Try this instead:

Dim Array1

Redim Array1(20)
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6328283
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
 
LVL 38

Expert Comment

by:PaulHews
ID: 6328335
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
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6328367
Oh yea...  Now I see it... looked at it 3 times and didn't notice that  :)  Time to go home  :)
0
 
LVL 5

Expert Comment

by:aminerd
ID: 6329093
Public Sub Something(Array As Variant)
0
 
LVL 3

Accepted Solution

by:
BGillham earned 164 total points
ID: 6333597
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now