3

I have this enumeration

Public Enum Applications
    Unknown = 0
    AA = 1
    BB = 2
    CC = 3  
End Enum


Private Const CALLING_APP As Applications= Applications.CC

CALLING_APP.ToString() is giving me "3". But I want "CC" - what am I doing wrong?

M4N
  • 94,805
  • 45
  • 217
  • 260
Pratap Das
  • 504
  • 2
  • 7
  • 20
  • Are u sure? try something like `Dim s = CALLING_APP.ToString` what do u get? – Yuriy Galanter Dec 03 '13 at 19:39
  • see [MSDN examples and explanation](http://msdn.microsoft.com/en-us/library/16c1xs4z(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-4). Just remember to switch the code example to VB in case this link does not do that. – quetzalcoatl Dec 03 '13 at 19:47
  • See the "notes to callers" section. Simply calling ToString should return the name. If it does not, something other must be wrong. Try using precisely that example. What does it return? What's your VB/.Net version. I'm asking just in case. Is it ie in-Excel VBA or something? – quetzalcoatl Dec 03 '13 at 19:50

2 Answers2

4

Pass "F" as parameter for the ToString() method: CALLING_APP.ToString("F")

alu
  • 759
  • 7
  • 20
3

try this:

Private CALLING_APP As Applications= Applications.CC    ' no "Const"
' CALLING_APP.ToString will return CC

Const can apparently change how NET recognizes the constant. As a Const, I get Cannot find the method on the object instance while Intellisense "sees" it correctly. If you must use Const for some reason, you can get the text return this way:

Dim strName as string = [Enum].GetName(GetType(Applications), CALLING_APP ))

It is basically what .ToString does for us behind the scenes. Typed as it is, your code should work.

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178