Empty Arrary when VBScript calls VB COM object. 
Author Message
 Empty Arrary when VBScript calls VB COM object.

I am writing VBScript for an ASP which calls a COM object I've written
in VB.  The function on the COM object has multiple recordsets returned
from an ADO call to the database.  Data if pulled from the recordsets
and is placed into an array filled with 'n' number of 2-dimensional
arrays.

I created a form in VB for testing and was able to call the function on
the COM object successfully.  It returned the array full of data.
However, when I tried to call this function from VBScript it didnt
return anything.  Are VB and VBScript's array objects such different
animals that they cannot communicate directly?

I tried rewriting the COM object function as a sub, passing a byref
variant parameter, but to no avail.

I'm unsure if I'm writing this incorrectly or if there is a bug in the
way VB and VBScript's arrays interact.  Any suggestions?

Below you will find the COM object function in VB...below it you'll
find the VBScript:

Thanks in advance for your help,
Kelly McCullough
___________________________________
Public Function GetCodes() As Variant

    Dim cn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset
    Dim params As ADODB.Parameters
    Dim param As ADODB.Parameter
    Dim j As Integer
    Dim i As Integer
    Dim intCount As Integer
    Dim arr()
    Dim intMvarCodesUbound As Integer

    '<Database calling code removed>
    Set rs = cmd.Execute

    j = 0
    Do While rs.State <> adStateClosed

        intCount = rs.RecordCount - 1
        ReDim arr(intCount, 3)
        For i = 0 To intCount
            arr(i, 0) = rs(CategoryID)
            arr(i, 1) = rs(CodeID)
            arr(i, 2) = rs(CodeValue)
            arr(i, 3) = rs(Order)
            rs.MoveNext
        Next i
        mvarCodes(j) = arr
        Set rs = GetNextRecordSet(rs)
        j = j + 1
    Loop

    GetCodes = mvarCodes
end function

Private Function GetNextRecordSet(ByVal rs As Recordset)
    Set GetNextRecordSet = rs.NextRecordset
End Function

--------------------------------------
VBSCRIPT
--------------------------------------
Dim arr
Dim objCode

Set objCode = Server.CreateObject("SMSBusObjs.cCode")

arr = objCode.GetCodes

Sent via Deja.com
http://www.*-*-*.com/



Mon, 14 Jul 2003 10:21:16 GMT  
 Empty Arrary when VBScript calls VB COM object.
A VBScript array is a SAFEARRAY the same as VB/VBA with only one catch - it must be a SAFEARRAY of
variants...

How is mvarCodes defined?

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> I am writing VBScript for an ASP which calls a COM object I've written
> in VB.  The function on the COM object has multiple recordsets returned
> from an ADO call to the database.  Data if pulled from the recordsets
> and is placed into an array filled with 'n' number of 2-dimensional
> arrays.

> I created a form in VB for testing and was able to call the function on
> the COM object successfully.  It returned the array full of data.
> However, when I tried to call this function from VBScript it didnt
> return anything.  Are VB and VBScript's array objects such different
> animals that they cannot communicate directly?

> I tried rewriting the COM object function as a sub, passing a byref
> variant parameter, but to no avail.

> I'm unsure if I'm writing this incorrectly or if there is a bug in the
> way VB and VBScript's arrays interact.  Any suggestions?

> Below you will find the COM object function in VB...below it you'll
> find the VBScript:

> Thanks in advance for your help,
> Kelly McCullough
> ___________________________________
> Public Function GetCodes() As Variant

>     Dim cn As ADODB.Connection
>     Dim cmd As ADODB.Command
>     Dim rs As ADODB.Recordset
>     Dim params As ADODB.Parameters
>     Dim param As ADODB.Parameter
>     Dim j As Integer
>     Dim i As Integer
>     Dim intCount As Integer
>     Dim arr()
>     Dim intMvarCodesUbound As Integer

>     '<Database calling code removed>
>     Set rs = cmd.Execute

>     j = 0
>     Do While rs.State <> adStateClosed

>         intCount = rs.RecordCount - 1
>         ReDim arr(intCount, 3)
>         For i = 0 To intCount
>             arr(i, 0) = rs(CategoryID)
>             arr(i, 1) = rs(CodeID)
>             arr(i, 2) = rs(CodeValue)
>             arr(i, 3) = rs(Order)
>             rs.MoveNext
>         Next i
>         mvarCodes(j) = arr
>         Set rs = GetNextRecordSet(rs)
>         j = j + 1
>     Loop

>     GetCodes = mvarCodes
> end function

> Private Function GetNextRecordSet(ByVal rs As Recordset)
>     Set GetNextRecordSet = rs.NextRecordset
> End Function

> --------------------------------------
> VBSCRIPT
> --------------------------------------
> Dim arr
> Dim objCode

> Set objCode = Server.CreateObject("SMSBusObjs.cCode")

> arr = objCode.GetCodes

> Sent via Deja.com
> http://www.deja.com/



Mon, 14 Jul 2003 11:56:46 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Call VB DLL or COM object from within VB COM object or EXE

2. call to COM object returns empty variant array???

3. com object will not read registry when com object called from asp (vb works fine)

4. VBScript calling to a COM object that expects a user-defined object

5. Stepping into a VB COM object called from ASP

6. Type Mismatch Error calling VB COM component from VBScript

7. Calling COM object from VBscript

8. speed difference between vbscript and vb com object????

9. Creating VB COM object to access Jscript from VBScript

10. returning empty variant array from COM object?

11. Type Mismatch Error calling VB COM component from VBScript

12. speed difference between vbscript and vb com object????

 

 
Powered by phpBB® Forum Software