Solved

Using an enum for a property in a class module

Posted on 2006-11-09
10
750 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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
 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

785 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