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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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
damonfCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pkchaturvediAuthor Commented:
Answer accepted
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.