CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    41

    Passing a variable into a Function - Help!!!

    hi

    I have a DLL called ReportMgr. I am trying to test it using a test project.

    In the DLL there's multiuse class called CReportManager with two public variables DBConnectionString and DBProvider as strings There's a Public Function EstablishConnection(ByRef cnn, ByVal DBConnectionString, ByVal DBProvider) As Boolean in a module.
    The fn is as follows.


    Public Function EstablishConnection(ByRef cnn, ByVal DBConnectionString, ByVal DBProvider) As Boolean
    If DBConnectionString = "" Or DBProvider = "" Then
    MsgBox "Insufficeint data to establish link to ProdMan database", vbCritical, "ProdMan Report Manager"
    EstablishConnection = False
    End If
    If cnn.State <> adStateOpen Then
    cnn.ConnectionString = DBConnectionString
    cnn.Provider = DBProvider
    cnn.Open
    End If
    EstablishConnection = True
    End Function#


    In the test project I am seting the DBConnectionString and DBProvider by creating an instance of the cls CReportManager. My problem is that these are not passed to the function when I call the fn in another class in the DLL. That sub-routine is below.
    Can somone please help.

    Cheers
    Vijja


    Public Sub OpenGOALrecordSet() ' Opens goal recordset **********************************
    Dim SQL1 As String
    Dim rstGOAL As New ADODB.Recordset

    SQL1 = "SELECT Fld.MODEL_TYPE, Fld.MODEL_NAME, Fld.MODEL_PATH FROM FIELD_MODEL_DTLS AS Fld " & _
    "WHERE (((Fld.MODEL_TYPE)='GOAL'))ORDER BY Fld.MODEL_TYPE, Fld.MODEL_NAME, Fld.MODEL_PATH;"


    Call EstablishConnection(cnn, DBConnectionString, DBProvider)


    If cnn.State = adStateOpen Then
    rstGOAL.Open SQL1, cnn, adOpenForwardOnly, adLockReadOnly
    GOALarray = rstGOAL.GetRows
    rstGOAL.Close
    End If
    End Sub



  2. #2
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Re: Passing a variable into a Function - Help!!!

    try using option explicit at the top of this module and then stepping through the code and determining when the variables get their values. it's possible that OpenGOALrecordSet() does not have access to DBConnectionString and DBProvider without using the . operator. you may need to do Call EstablishConnection(cnn, myCReportManager.DBConnectionString, myCReportManager.DBProvider)
    Also, what is the scope of cnn?



    thanx/good luck,
    adam
    thanx/good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured