Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Array Expected

hi,
i have 2 ActiveX DLL, the first one with the following code:-

Private Type paraList
  VarValue As Variant
  DataType As Variant
  Size As Integer
  Direction As Integer
End Type

Public Enum QUERYOPTIONS
    QO_UseTable = ADODB.adCmdTable
    QO_UseText = ADODB.adCmdText
    QO_UseStoredProc = ADODB.adCmdStoredProc
    QO_UseUnknown = ADODB.adCmdUnknown
    QO_UseDefault = -1
End Enum

Public Enum LOCKTYPES
    LT_ReadOnly = ADODB.adLockReadOnly
    LT_Optimistic = ADODB.adLockOptimistic
    LT_Pessimistic = ADODB.adLockPessimistic
    LT_BatchOptimistic = ADODB.adLockBatchOptimistic
End Enum

Public Enum CURSORLOCATION
    CURL_Client = ADODB.adUseClient
    CURL_Server = ADODB.adUseServer
End Enum

Public Enum CURSORTYPE
    CURT_OpenKeySet = ADODB.adOpenKeyset
End Enum

Public Enum E_ConnType
     Local_Conn = 0
     Remote_Conn = 1
End Enum

Private Const OBJNAME = "DataAccess Component"
Private Cnn As ADODB.Connection
Private Cmd As ADODB.Command
'''Private Outernalconnstr As String

'Connection String that Contains the Lookups Data Source
Private Const Internalconnstr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SBOS EH;Data Source=SBOS_SERVER"
Private Const Outernalconnstr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SBOS EH;Data Source=SBOS_SERVER"

Public Function CloseConnection() As Boolean
    If Not Cnn Is Nothing Then
'        Cnn.Close
        Set Cnn = Nothing
    End If

End Function

Public Function OpenConnection(ByVal Connect As String) As Boolean
Dim lErrNo      As Long
Dim sErrDesc    As String

    'assume failure
    OpenConnection = False
   
    'enable error handler
    On Error GoTo ErrorHandler
   
    'establish the transaction if Connection String specified
    If Connect <> vbNullString Then
        CloseConnection
        Set Cnn = New ADODB.Connection
        Cnn.Open Connect
        'MsgBox "Connected"
    End If
   
    OpenConnection = True
    Exit Function
   
ErrorHandler:

    'store incoming values and raise error
    lErrNo = Err.Number
    sErrDesc = Err.Description
    On Error GoTo 0
    Err.Raise lErrNo, OBJNAME, sErrDesc

End Function

Public Function ExecuteSp(ByRef rs As ADODB.Recordset, ByVal spName As String, ByVal ConnType As Integer, ByRef AttachedParameters() As paraList) As Boolean
Dim i As Long
Dim lErrNo      As Long
Dim sErrDesc    As String

On Error GoTo ErrorHandler
   ' If RS Is Nothing Then
        Set rs = New ADODB.Recordset
   ' End If
 
    Set Cmd = New ADODB.Command

    If rs.State = adStateOpen Then
        rs.Close
    End If
With rs
    .CURSORTYPE = CURT_OpenKeySet
    .LockType = LT_Optimistic
    .CURSORLOCATION = CURL_Client
End With
  ExecuteSp = True
    'Is used for DataBase Connection String
    If ConnType = Local_Conn Then
      OpenConnection (Outernalconnstr)
    Else
    'Is used for Cashing Connection String
      OpenConnection (Internalconnstr)
    End If
     Cmd.CommandTimeout = 3600
     Cmd.ActiveConnection = Cnn
     Cmd.CommandType = QO_UseStoredProc
     Cmd.CommandText = Trim(spName)
        If (UBound(AttachedParameters) > 0) Then
           'Cmd.Parameters.Refresh
            For i = 1 To UBound(AttachedParameters)
                If AttachedParameters(i).VarValue = "" Then
                    Cmd.Parameters(i).Value = Null
                Else
                    Cmd.Parameters(i).Type = AttachedParameters(i).DataType
                    Cmd.Parameters(i).Direction = AttachedParameters(i).Direction
                    Cmd.Parameters(i).Size = AttachedParameters(i).Size
                    Cmd.Parameters(i).Value = AttachedParameters(i).VarValue
                End If
            Next i
        End If
        ReDim AttachedParameters(0)
     rs.Open Cmd
     Exit Function
ErrorHandler:
    'store incoming values
    lErrNo = Err.Number
    sErrDesc = Err.Description
   
    'close down what we can and raise error
    On Error Resume Next
        Set rs = Nothing
    On Error GoTo 0
        ExecuteSp = False
        Set rs.ActiveConnection = Nothing
        Err.Raise lErrNo, OBJNAME, sErrDesc
End Function

Private Sub Class_Terminate()
'clean up any outstanding connections
    CloseConnection
    Set Cmd = Nothing
End Sub

The Second Dll have a Refrence from the First DLL and here is the Code :-

Public Enum E_ConnType
     Local_Conn = 0
     Remote_Conn = 1
End Enum

Private Type paraList
  VarValue As Variant
  DataType As String
  Size As Integer
  Direction As Integer
End Type

Private Const scGET_DISCONNECTEDCANCELEDTELEPHONES = "ccGetDisconnectedCanceledTelephones"
Dim obj_Da As PrjDA.clsDA
Public Function GetDisconnectedCanceledTelephones(BO_RS As ADODB.Recordset, ByRef AttachedParameters As paraList) As Boolean
Dim DO_RS As ADODB.Recordset

GetDisconnectedCanceledTelephones = False

' Execute stored procedure and return recordset
Set obj_Da = New PrjDA.clsDA
If obj_Da.ExecuteSp(DO_RS, scGET_DISCONNECTEDCANCELEDTELEPHONES, Remote_Conn, AttachedParameters()) Then
     Set BO_RS = DO_RS
     Set DO_RS = Nothing
     GetDisconnectedCanceledTelephones = True
    End If
Set obj_Da = Nothing
End Function


but unfortunately i'm getting an error in the second Dll at the Line of calling the function "obj_Da.ExecuteSp", Compiler Error Expected Array, at the Line :AttachedParameters()

Any Idea?
rgrds
Meer.
0
mirghani
Asked:
mirghani
  • 4
  • 3
1 Solution
 
NPluisCommented:
I think you should change this part:

Public Function GetDisconnectedCanceledTelephones(BO_RS As ADODB.Recordset, ByRef AttachedParameters As paraList)

to:

Public Function GetDisconnectedCanceledTelephones(BO_RS As ADODB.Recordset, ByRef AttachedParameters() As paraList)

This way you pass an array to the function in your dll as well.
0
 
mirghaniAuthor Commented:
hi NPluis,
i'm getting another Compiler Error:-
"ByRef Argument Type Mismatch" !!!!
really it's making me feeling board:-(
Meer.
0
 
NPluisCommented:
Change Private Type paraList to Public in the first dll and use that in the second in stead of making another type. I guess that's the problem now
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mirghaniAuthor Commented:
hi,
it works fine but i'm facing the same error:-
"ByRef Argument Type Mismatch" in the third DLL.
where i obtain the error, here is the code for the third DLL which have a refrence for the second DLL.
here is the code:-

Public Type paraList
  VarValue As Variant
  DataType As Variant
  Size As Integer
  Direction As Integer
End Type

Dim AttachedParameters() As paraList

Private Const mVarChar = adVarChar
Private Const mInt = adInteger
Private Const mTinyInt = adTinyInt
Private Const mSmallInt = adSmallInt
Private Const mDateTime = adDBTimeStamp
Private Const mChar = adChar
Private Const mMoney = adCurrency
Private Const mGUID = adGUID

Private Const scGET_DISCONNECTEDCANCELEDTELEPHONES = "ccGetDisconnectedCanceledTelephones" 'REPBO

Dim obj_REPBO As PrjREP.clsREP 'Report Business Object
Dim Count As Integer

'Public Sub Instantiate_Object(SourceObj_Name As Object, DestObj_Name As Object)
'  Set SourceObj_Name = New DestObj_Name
'End Sub
'
'Public Sub Release_Object(Obj_Name As Object)
' Set Obj_Name = Nothing
'End Sub

'=======================================================================
'Synopsis:              Executes stored procedure to Get Disconnected Canceled Telephones
'Function input:        SiteID,Disconnected,UserName,CategeryID,CabinetNo,FromDate,ToDate,FromBalance,ToBalance
'Function output:       RecordSet
'=======================================================================
Public Function GetDisconnectedCanceledTelephones(BO_RS As ADODB.Recordset, ByVal SiteID As Integer, _
                                 ByVal Disconnected As Integer, ByVal UserName As String, _
                                 ByVal CateogeryID As Integer, ByVal CabinetNo As Integer, _
                                 ByVal FromDate As Date, ByVal ToDate As Date, _
                                 ByVal FromBalance As Currency, ByVal ToBalance As Currency) As Boolean
Dim DO_RS As ADODB.Recordset
Count = 1

GetDisconnectedCanceledTelephones = False

' Execute stored procedure and return recordset

'Instantiate_Object obj_REPBO, REPBO.cREPBO

Set obj_REPBO = New PrjREP.clsREP

AssignParameters Count, SiteID, mSmallInt, 2, adParamInput
AssignParameters Count, Disconnected, mTinyInt, 1, adParamInput
AssignParameters Count, UserName, mVarChar, 100, adParamInput
AssignParameters Count, CateogeryID, mVarChar, 255, adParamInput
AssignParameters Count, CabinetNo, mSmallInt, 2, adParamInput
AssignParameters Count, FromDate, mDateTime, 4, adParamInput
AssignParameters Count, ToDate, mDateTime, 4, adParamInput
AssignParameters Count, FromBalance, mMoney, 8, adParamInput
AssignParameters Count, ToBalance, mMoney, 8, adParamInput
If obj_REPBO.GetDisconnectedCanceledTelephones(DO_RS, AttachedParameters()) Then
     Set BO_RS = DO_RS
     Set DO_RS = Nothing
     GetDisconnectedCanceledTelephones = True
    End If

'Release_Object obj_REPBO

Set obj_REPBO = Nothing

End Function

Private Sub AssignParameters(ByRef Counter As Integer, ByVal VarValue As Variant, _
                            ByVal DataType As Variant, ByVal Size As Integer, ByVal Direction As Integer)
ReDim Preserve AttachedParameters(Counter)
AttachedParameters(Counter).VarValue = VarValue
AttachedParameters(Counter).DataType = DataType
AttachedParameters(Counter).Size = Size
AttachedParameters(Counter).Direction = Direction
Counter = Counter + 1
End Sub

rgrds.
Meer.
0
 
mirghaniAuthor Commented:
i removed from the second DLL the Decalration of Type ParaList and used that in First DLL and it works fine.
but when i came to add 2nd DLL as Refrence to the 3rd DLL i'm getting Compile Error"ByRef Argument Type Mismatch" at the Line:
If obj_REPBO.GetDisconnectedCanceledTelephones(DO_RS, AttachedParameters())
rgrds.
Meer.
0
 
mirghaniAuthor Commented:
hi,
if i add 1st DLL which Contains the Declaration of Type ParaList it will work fine but i don't want to add Refrence DLL 3 to DLL 1 , i hope u got my point.
rgrds.
Meer.
0
 
NPluisCommented:
Then you can't do it and should just give all the items of the type seperatly to the functions. Since it are only four items (two variants and two integers it shouldn't be such a deal. The error states that the type the type you give to the function isn't the same as he expects. The fact that you give it the same name and form doesn't make it the same.



0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now