Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 756
  • Last Modified:

Using an enum for a property in a class module

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
cquinn
Asked:
cquinn
  • 6
  • 4
1 Solution
 
Leigh PurvisDatabase DeveloperCommented:
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
 
cquinnAuthor Commented:
I have tried all of that, but no joy

0
 
Leigh PurvisDatabase DeveloperCommented:
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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
cquinnAuthor Commented:
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
 
Leigh PurvisDatabase DeveloperCommented:
OK, hang on - I'll try it with your actual example.
0
 
Leigh PurvisDatabase DeveloperCommented:
Nope - works perfectly.
Very odd.
0
 
cquinnAuthor Commented:
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
 
Leigh PurvisDatabase DeveloperCommented:
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
 
cquinnAuthor Commented:
I changed the type in the Property Get and shazzam!  Intellisense works!  

Many thanks

Chris
0
 
Leigh PurvisDatabase DeveloperCommented:
Most welcome.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now