?
Solved

Get Recordset / Vaiiable(s) from DLL to VB

Posted on 2003-03-05
2
Medium Priority
?
164 Views
Last Modified: 2010-04-07
Hi Experts,

Could you please provide me an example for this :

1) How to make a VB DLL to return Recordset to VB (is it possible)?

2) How to make a VB DLL to return Variable(s) to VB?

3) How to code in the VB to receive the return from (1) ,   (2)?

Thanks a lot
kchoed
0
Comment
Question by:kchoed
[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
2 Comments
 
LVL 7

Expert Comment

by:Smallint
ID: 8078290

In Class module of DLL for example:

'Set This variables in e.g. Class_Initialize
dim strClassVariable as string

dim rsClassRecordset as string

Public Property Get ReturningVariable() As String
    ReturningVariable = strClassVariable
End Property

Public Function ReturnsRecordset() As ADODB.Recordset
   set ReturningRecordset = rsClassRecordset
end function


In your EXE:

Set obj = new NameOfYourClass

strFromDLL = obj.ReturningVariable

set rsFromDLL = obj.ReturnsRecordset()


0
 
LVL 43

Accepted Solution

by:
TimCottee earned 800 total points
ID: 8078607
Indeed Smallint is close,

Your class might look something like this:

Private cnnInformation As ADODB.Connection
Private rstInformation As ADODB.Recordset
Private strInformation As String

Private Sub Class_Initialize()
  'Set default values and initialise connection object
  strInformation = "Hello there"
  Set cnnInformation = New ADODB.Connection
  cnnInformation.ConnectionString = "Your connection string here"
  cnnInformation.Open
End Sub

Private Sub Class_Terminate()
  'Properly tidy up and release our recordset and connection objects
  If Not (rstInformation Is Nothing) Then
    If rstInformation.State <> adStateClosed Then
      rstInformation.Close
    End If
    Set rstInformation = Nothing
  End If
  If Not (cnnInformation Is Nothing) Then
    If cnnInformation.State <> adStateClosed Then
      cnnInformation.Close
    End If
    Set cnnInformation = Nothing
  End If
End Sub
   
Public Property Let StringInfo(ByVal NewValue As String)
  strInformation = NewValue
End Property

Public Property Get StringInfo() As String
  StringInfo = strInformation
End Property

Public Property Get RecordsetInfo() As ADODB.Recordset
  Set rstInformation = New ADODB.Recordset
  rstInformation.Open "Select Statement Here",cnnInformation,adOpenStatic,adLockOptimistic
  Set RecordsetInfor = rstInformation
End Property


You can then use in your form:

Private Sub Command1_Click()
  Dim MyClass As DLLProject.Class1
  Set MyClass = New DLLProject.Class1
  With MyClass
    Msgbox .StringInfo
    .StringInfo = "Goodbye"
    Msgbox .RecordsetInfo.Fields.Count
    Msgbox .StringInfo
  End With
  Set MyClass = Nothing
End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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 Month12 days, 1 hour left to enroll

752 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