?
Solved

Array Expected

Posted on 2003-02-24
7
Medium Priority
?
213 Views
Last Modified: 2010-05-01
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
Comment
Question by:mirghani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:NPluis
ID: 8015187
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
 

Author Comment

by:mirghani
ID: 8015312
hi NPluis,
i'm getting another Compiler Error:-
"ByRef Argument Type Mismatch" !!!!
really it's making me feeling board:-(
Meer.
0
 
LVL 2

Expert Comment

by:NPluis
ID: 8015344
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mirghani
ID: 8015607
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
 

Author Comment

by:mirghani
ID: 8015620
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
 

Author Comment

by:mirghani
ID: 8015719
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
 
LVL 2

Accepted Solution

by:
NPluis earned 400 total points
ID: 8015764
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question