Calling Vb Dll method from ASP

Hi!
I am calling a VB dll method and a function from ASP.My VB function has an variant aggument and returns the variant array. when calling that from ASP it gives type mismatch error.
The function is like that:

Public Function Apptest(iCount As Variant) As Variant()
    Dim sArray(2) As Variant
   
    sArray(1) = "Pradeep"
    sArray(2) = "Kumar"
   
    iCount = 1
   
    Apptest = sArray
End Function
**** AND i am calling that method like that: i have created the the object and assign it an declared aaray in server ASPscript like that  asLocations =  ServerComp.Apptest (iLocation)  
 
Is ASP support this. I mean it is possible to pass a variant array in the method of VB dll.  


I need immediate held
Thanks in advance

pkchaturvedi@hotmail.com
pkchaturvediAsked:
Who is Participating?
 
damonfConnect With a Mentor Commented:
Check out MS KB Q197956.  I've done quite a bit with calling vb functions from ASP and returning variants.  Basically the rule is:  if you want to pass variant arrays from ASP, you have 1) declare the variable as variant (e.g. dim thisArray) not an array
2) pass the variable by reference.

I'm thinking your code is broke because 1) your variant arg is actually being passed ByVal since you declared it as an array, not a variant.  So VB chokes.
2) You're trying to return a value, which I think by definition is ByVal.

Here's what I do:

In VB:

public function RetArray( _
    ByRef thisArray as Variant) as string
    'do stuff
    thisArray = 'some array
    RetArray = 'string of any error
end function

Basically if the function returns nothing, you succeeded and thisArray now contains what you want.

In ASP, I do:

dim thisArray

myObj = Server.CreateObject("foo.bar")
sRetval = myObj.RetArray(thisArray)

It took many aspirin before I figured this out, so good luck.

HTH
0
 
aaronvmiCommented:
Remove the As Variant as shown below and you should not have any problems.

Public Function Apptest(iCount As Variant)
    Dim sArray(2) As Variant
     
    sArray(1) = "Pradeep"
    sArray(2) = "Kumar"
     
    iCount = 1
     
    Apptest = sArray
End Function
0
 
jbathijaCommented:
Public Function Apptest(byval iCount As Variant) As Variant()
or
Public Function Apptest(byval iCount As Variant) As Variant

try using this
   
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
DawsonBCommented:
if jbathija's suggestoin doesn't work,
could you paste the code from the asp where you first of all declare your variable and then where you call your dll?
0
 
MarineCommented:
Public Function Apptest(iCount As Variant) As Variant()
    Dim sArray(2) As Variant
    sArray(1) = "Pradeep"
    sArray(2) = "Kumar"
    iCount = 1
    Apptest = sArray
End Function
This is bad example. First you limit your array size you can easily make a mistake in Asp without knowing the bounds then you already have some values in it which are going to be overwritten.
0
 
sarmadCommented:
Try this
Public Function Apptest(iCount As Variant) As Variant
    Dim sArray(2) As Variant
     
    sArray(1) = "Pradeep"
    sArray(2) = "Kumar"
     
    iCount = 1
     
    Apptest = sArray
End Function
0
 
pkchaturvediAuthor Commented:
Answer accepted
0
All Courses

From novice to tech pro — start learning today.