Re: Type mismatch calling a COM object developed in vb6




Dag Sunde wrote:
<wolfing1@xxxxxxxxx> wrote in message
news:1140017091.779500.182890@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Dag Sunde wrote:
<spkelly@xxxxxxxxxxxxx> wrote in message
news:1139947917.518866.101060@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Michael B. Johnson wrote:
On Mon, 13 Feb 2006 19:46:49 GMT, "Veign" <NOSPAMveign1@xxxxxxxxx>
wrote:

Did you try:
response.write obj.test(cstr(k))

Chris is right: the OP's problem is that he needs to cast the variant
in
the ASP
page to the string type expected by the VB procedure.

Couldn't he also just change the dim statement to

dim k as string

cstr(x) is probably safer...

just curious

As I have posted earlier in this thread...

If you want to call a method in a VB Com component from
an .ASP page, all the parameters for that method *must*
be declared By Value in the component:

public function test( ByVal a as string)
... ^^^^^
end function

--
Thanks all for your responses. I changed the function declaration to
be all variants and it works.
But what you said above is boggling. Do you mean I can't pass
parameters to .COM objects by reference? In another COM object I'm
writing right now (haven't tested yet), I was passing parameters
(byref) that were going to be filled out by the COM object, do you mean
I can't do that? How would I do that if all parameters must be passed
Byval?

Declare a class with all the public properties you'll need,
and use an instance of that class as a returnvalue from
your function...

Public class CUser
Public Name as string
Public Phone as string
Public Age as long
...

In your function:

Public function getUser(byVal userId as long) as CUser
....
' get all userdata...
getDataFromId(userId)
Dim oUser as CUser
Det oUser = New CUser
oUser.Name = blablaName
oUser.Phone = blablaPhone
oUser.Age = BalAge

Set getUser = oUser

End Function


In .Asp

Dim o
Set o = Server.CreateObject("Comp.Class")

Dim oUser
Set oUser = o.getUser(12)
Response.Write oUser.Name
Response.Write oUser.Phone
Response.Write oUser.Age
...

(...Or something like that...)

--
Dag.
Thanks all for your posts, it's a lot of info I didn't know, never
programmed COM objects before, specially not ones to be used by ASP.
Now if you can check on this situation that is giving me problems
(going to change the 'As Variant' for a byval with the real type later,
but I don't think that's the problem):
[COM Object]
public class ProdOrd
Public prodcode As String
Public qty As Single
....
end class

Now how do I pass an array of ProdOrd to a function in the COM object?:
Public Function checkav(session As Variant, requestlist As Variant,
Optional shipstate As Variant = "") As ProdOrd()
dim arrResult(1) as ProdOrd
set arrResult(0) as new prodord
set arrResult(1) as new prodord
arrResult(0).prodcode = "a"
arrResult(1).prodcode = "b"
checkav = arrResult
end function


And in ASP the following call gives me a type mismatch error:
dim r
dim o
dim pr(1)
set o = server.createobject("products.product")
set pr(0).prodcode = "x"
set pr(1).prodcode = "y"
r = o.checkav("1",pr, "NY") 'This line runs fine
response.write ubound(r) 'This returns 1, so far so good
response.write r(0).prodcode 'ERROR: Type mismatch


How can I access the fields inside the resulting array?

.



Relevant Pages

  • Re: Type mismatch calling a COM object developed in vb6
    ... Now how do I pass an array of ProdOrd to a function in the COM object?: ... Public Function checkav(session As Variant, requestlist As Variant, ... dim arrResultas ProdOrd ... See if that helps on the result in your .ASP script. ...
    (comp.lang.basic.visual.misc)
  • Re: My COM always writes two same data in the system
    ... classic ASP way but going through a vb6.0-based Active X DLL file. ... However it always adds two identical records at the same time. ... Public Function AddNotes(SID As Variant, RID As Variant, Topic As ... Dim conn As ADODB.Connection ...
    (microsoft.public.inetserver.asp.components)
  • Re: Type mismatch calling a COM object developed in vb6
    ... Now how do I pass an array of ProdOrd to a function in the COM object?: ... Public Function checkav(session As Variant, requestlist As Variant, ... dim arrResultas ProdOrd ...
    (comp.lang.basic.visual.misc)
  • Re: shape range help
    ... However initial use of Dim() avoided use of brackets and he ... Everytime with ReDim only, I get a Variant() ... never in a session I don't do the initial Dim varr() then redim does NOT ...
    (microsoft.public.excel.programming)
  • Re: Coding with varsortby and options
    ... Dim varhowsort As Variant ... DoCmd.OpenReport stDocName, acViewPreview ...
    (microsoft.public.access.formscoding)