Using Enum

  • Thread starter Thread starter Herfried K. Wagner [MVP]
  • Start date Start date
H

Herfried K. Wagner [MVP]

* "Tiraman said:
I have 2 Questions About Using Enum

1) i have the following Enum under my class but if i need to use it i must
use it like this

ConstantsFileSystem.CREATE_FILE

how can i use it just by the const name by doing like this CREATE_FILE

Public Enum ConstantsFileSystem

CREATE_FILE = 0

APPEND_FILE = 1

OVERWRITE_FILE = 2

End Enum

'Imports ConstantsFileSystem' on top of the file in which you want to
use the constants without qualifying them (I am not sure that this makes
much sense).
2) is it good to use Enum for public params which i need to use all over my
Assemblies ? (if not please recommend a better way)

Why not?
 
Tiraman said:
Hi ,

I have 2 Questions About Using Enum

1) i have the following Enum under my class but if i need to use it i
must use it like this

ConstantsFileSystem.CREATE_FILE

how can i use it just by the const name by doing like this
CREATE_FILE

Public Enum ConstantsFileSystem

CREATE_FILE = 0

APPEND_FILE = 1

OVERWRITE_FILE = 2

End Enum

Why? CREATE_FILE and the other constants could also be part of another Enum.
In addition, auto-complete automatically inserts the full name, so I don't
see the problem.

(BTW, there is System.IO.FileMode already)
2) is it good to use Enum for public params which i need to use all
over my Assemblies ? (if not please recommend a better way)

Well, I think it's good. :-)


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Hi ,

I have 2 Questions About Using Enum

1) i have the following Enum under my class but if i need to use it i must
use it like this

ConstantsFileSystem.CREATE_FILE

how can i use it just by the const name by doing like this CREATE_FILE

Public Enum ConstantsFileSystem

CREATE_FILE = 0

APPEND_FILE = 1

OVERWRITE_FILE = 2

End Enum

2) is it good to use Enum for public params which i need to use all over my
Assemblies ? (if not please recommend a better way)


Best Regards ,

Tiraman :-)
 
Hi,

Well you are right .
i added the import in the top of my assembly and i added a reference to the
file which is a regular TLB file and not a DOT NET file !
And now its ok .

BUT when i m trying to compile my DLL i m getting the following error :

vbc : error BC31011: Unable to load referenced library
'c:\DLL\NanaConstants.tlb': System Error &H8013110b&
c:\DLL\NanaConstants.tlb : error BC31011: Unable to load referenced
library 'c:\DLL\NanaConstants.tlb': System Error &H8013110b&
vbc : error BC30142: Unable to generate a reference to file
'c:\DLL\NanaConstants.tlb'
(use TLBIMP utility to reference COM DLLs): unable to load
international DLL: VBC7ui.dll
C:\Components\General.vb(6) : error BC30466: Namespace or type
'ConstantsFileSystem' for the Imports 'NanaLib.ConstantsFileSystem' cannot
be found.

Imports NanaLib.ConstantsFileSystem
~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Components\General.vb(93) : error BC30451: Name 'naCREATE_FILE' is
not declared.

Optional ByVal Method As Integer =
naCREATE_FILE, _

~~~~~~~~~~~~~
 
Hello Armin ,

you are right about the FileMode but i m asking in general
lets say that i have my own Enum but they are all in an old TLB file (which
is not in .NET) and i read that i can import and reference it to my project
and then it will be recognized all over which is true but as i wrote b4 i m
have problems with the compilation .

10x
 
Tiraman said:
Hi,

Well you are right .
i added the import in the top of my assembly and i added a reference
to the file which is a regular TLB file and not a DOT NET file !
And now its ok .

How did you add the reference? Either use "add reference" -> COM tab, or use
the tlbimp tool to create an interop wrapper dll that can be referenced by
pressing the "browse" button on the first folder of the "add reference"
dialog.
 
* "Tiraman said:
i added the import in the top of my assembly and i added a reference to the
file which is a regular TLB file and not a DOT NET file !
And now its ok .

The enum is defined inside a COM DLL?
 
well
first let me say that every thing ok now :-)
i used the tlbimp tool in order to convert the COM TLB
in to assembly and i put that assembly in the GAC
And now i m using it all over :-)

So 10x again to both of you .

Bye
 
Back
Top