Solved

Using an enum for a property in a class module

Posted on 2006-11-09
10
748 Views
Last Modified: 2010-09-08
I have written a class module to implement the Common Dialogue functionality using API calls without using the CommonDialog control, because of problems with versions on different machines

I am wanting to use an enum to prompt for acceptable values for a property at design time, but it does not work, where it does work in a normal module - for example:

Public enum sType
  First =1
  Second =2
  Third =3
end enum

Public Function GetType(sItem as sType) as integer
  GetType=sItem
end function

When you start to type a call to the function, as you type the ( a list of acceptable values (First, Second, Third)

If I do the same in a Property Let function in a class module, it doesn't work in the same way - what can I do so that it will e.g

clsCommonDialog - module definition

Public Enum cdlFlags
    cdlOFNReadOnly = &H1
    cdlOFNOVERWRITEPROMPT = &H2
    cdlOFNHIDEREADONLY = &H4
    cdlOFNNOCHANGEDIR = &H8
    cdlOFNSHOWHELP = &H10
    cdlOFNNOVALIDATE = &H100
    cdlOFNALLOWMULTISELECT = &H200
    cdlOFNEXTENSIONDIFFERENT = &H400
    cdlOFNPATHMUSTEXIST = &H800
    cdlOFNFILEMUSTEXIST = &H1000
    cdlOFNCREATEPROMPT = &H2000
    cdlOFNSHAREAWARE = &H4000
    cdlOFNNOREADONLYRETURN = &H8000
    cdlOFNNOTESTFILECREATE = &H10000
    cdlOFNNONETWORKBUTTON = &H20000
    cdlOFNNOLONGNAMES = &H40000
    cdlOFNEXPLORER = &H80000
    cdlOFNNODEREFERENCELINKS = &H100000
    cdlOFNLONGNAMES = &H200000
End Enum


Public Property Let Flags(vNewValue As cdlFlags)
' Code Header inserted by VBA Code Commenter and Error Handler Add-In
'=============================================================
' clsCommonDialog.flags
'-------------------------------------------------------------
'assign object's Flags property

    On Error GoTo HandleErr

    lFlags = vNewValue

ExitHere:
    Exit Property

    ' Error handling block added by VBA Code Commenter and Error Handler Add-In. DO NOT EDIT this block of code.
    ' Automatic error handler last updated at 24 May 2005 10:54:39
HandleErr:
    Select Case Err.Number
    Case Else
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "clsCommonDialog.flags"
    End Select
    ' End Error handling block.
End Property



=======================

dim cdl as New clsCommonDialog


With cdl
  .Flags = ..........................  Would like to be prompted with the list of options here when typing the code
end with

0
Comment
Question by:cquinn
  • 6
  • 4
10 Comments
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17905401
Umm it should be already.
Everything you have in place seems to be as it should.

The Enum is public...
The type is passed...

Have you tried (I know - the inevitable) compact, repair, decomp.
Checked there are no naming conflicts - either with built in objects - or other ones you have?

I'll keep looking at it to see if I notice anything.. :-S
0
 
LVL 15

Author Comment

by:cquinn
ID: 17905698
I have tried all of that, but no joy

0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17905878
Have you tried it in a new mdb - with nothing but your class imported.
Then a new module - instantiating your class, and looking for the intellisense.

Perhaps trying different property names?  (Other than Flags?)
0
 
LVL 15

Author Comment

by:cquinn
ID: 17906711
I've imported the class into a new db and created a new module, no joy

I've renamed the property to FileFlags - again no joy - still no intellisense
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17906936
OK, hang on - I'll try it with your actual example.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17906950
Nope - works perfectly.
Very odd.
0
 
LVL 15

Author Comment

by:cquinn
ID: 17913450
I have uploaded a simple database with my class module and a single form using it here:

The flags property is shown by intellisense when typing, but the enum values are not - I have also noticed that if I type a enum item in lower case (eg cdlofnreadonly when it is typed as cdlOFNReadOnly in the class module), it changes to lowercase in the class module!  Very strange!

https://filedb.experts-exchange.com/incoming/ee-stuff/1343-CDL.zip

0
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 125 total points
ID: 17913542
Hi.

I think the problem is in a slight inconsistency.
You require a variable of type cdlFlags passed to the Flags property Let call.
But in your property Get you've declared it as a Long.
If you change that to be cdlFlags too - then I reckon you'll get your intellisense back.

:-)
0
 
LVL 15

Author Comment

by:cquinn
ID: 17913684
I changed the type in the Property Get and shazzam!  Intellisense works!  

Many thanks

Chris
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17913688
Most welcome.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

18 Experts available now in Live!

Get 1:1 Help Now