Solved

Call a function Open

Posted on 2001-06-08
5
201 Views
Last Modified: 2010-05-02
Hi,

I am trying to create a class to wrap around an adodb recordset. I am trying to create a disconnected recordset. As a result, certain recordset commands (move next, etc) I want to pass to the recordset but other (open, etc) I want to handle myself. But anyways in terms of user friendliness I want to conform to the adodb recordset interface as much as possible. To do this I need to create a function called open. VB won't let me because open is a reserved word. Is there any way to get around this?

Zaphod.
0
Comment
Question by:Z_Beeblebrox
5 Comments
 
LVL 2

Expert Comment

by:kmv
ID: 6170537
You can create COM object in C/C++ which aggregate recordset object interfaces. I see that you have enouph experience for this.

Good luck!
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6171781
I want to write this in VB, not C++. Is there any way to create a class function called open in VB?

Zaphod.
0
 
LVL 2

Expert Comment

by:i_jester69
ID: 6172884
I know what you mean, but you are better off just naming your methods with descriptive(non-reserved) names like "OpenRecordset"
0
 
LVL 15

Accepted Solution

by:
ameba earned 0 total points
ID: 6174072
You can define interface IRecordset in type library, and then access your class clsRecorset via that interface.

' in clsRecordset
Implements IRecordset

' in your client's code:
    Dim rs As IRecordset
    Set rs = New clsRecordset
    rs.Open ...

' to create type library, you will need .IDL file, something like this
(I am not IDL expert, I copied this from Msado15.idl ;-))
// TypeLib : EX4.IDL (EX4)
// TargetFile : EX4.TLB

// UUID Usage:
// {3D6C1720-F527-11D3-A88C-ECBD3B289C70} : library EX4

[uuid(3D6C1720-F527-11D3-A88C-ECBD3B289C70),version(1.0),helpstring("Example 4 Library")]
library EX4
{
    importlib("STDOLE2.TLB");

    interface IRecordset;

    typedef [uuid(0000051B-0000-0010-8000-00AA006D2EA4)]
    enum {
        adOpenUnspecified = -1,
        adOpenForwardOnly = 0,
        adOpenKeyset = 1,
        adOpenDynamic = 2,
        adOpenStatic = 3
    } CursorTypeEnum;

    typedef [uuid(0000051D-0000-0010-8000-00AA006D2EA4)]
    enum {
        adLockUnspecified = -1,
        adLockReadOnly = 1,
        adLockPessimistic = 2,
        adLockOptimistic = 3,
        adLockBatchOptimistic = 4
    } LockTypeEnum;

    [
      odl,
      uuid(0000050E-0000-0010-8000-00AA006D2EA4),
      dual,
      nonextensible,
      oleautomation
    ]
    interface IRecordset : IUnknown {
        HRESULT _stdcall Move(
                        [in] long NumRecords,
                        [in, optional] VARIANT Start);
        [id(0x000003fa)]
        HRESULT _stdcall MoveNext();
        [id(0x000003fb)]
        HRESULT _stdcall MovePrevious();
        [id(0x000003fc)]
        HRESULT _stdcall MoveFirst();
        [id(0x000003fd)]
        HRESULT _stdcall MoveLast();
        [id(0x000003fe)]
        HRESULT _stdcall Open(
                        [in, optional] VARIANT Source,
                        [in, optional] VARIANT ActiveConnection,
                        [in, optional, defaultvalue(-1)] CursorTypeEnum CursorType,
                        [in, optional, defaultvalue(-1)] LockTypeEnum LockType,
                        [in, optional, defaultvalue(-1)] long Options);
        [id(0x000003ff)]
    };
}


Ref.:
IDL For VB Tutorial http://www.vb2themax.com/HtmlDoc.asp?Table=Articles&ID=130

Btw, it's easier to use word OpenRecordset.
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6211729
Seeing as how I accidentally posted this question for 0 points, I guess I'll just accept an answer rather than deleting the question.

Zaphod.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now