0

For a project i need to a Enum list writen in C++ converterd to en VB.net Enum list. So far everything is OK except for the #define enums that are in the C++ list. Here's what i whant to convert:

typedef enum
{
 #define EnumValue(a,b) a, b=a+255
 EnumValue(PARAM_Start,PARAM_END)
} ID;

As you can see this creates 255 enums values at runtime. How is this done in VB.net?

EDIT / SOLVED 30-09-2016
As mentioned below i made the wrong assumption by thinking it would create 255 enums, instead it creates just two enums however given PARAM_END an extra offset of 255. Meaning: if i have a three enums, the index of these enums are 0,1,3. Now if i want the index of ENUM_3 to begin at 10 i just add ENUM_2 + 8 this way ENUM_3 will start at index 10.

Thanks all for responding so fast and helping me out! :-)

4
  • 3
    It actually only creates 2, PARAM_Start and PARAM_END, of value 0 and 255 respectively. Commented Sep 29, 2016 at 14:16
  • There is no #define equivalent in VB .NET. Commented Sep 29, 2016 at 14:18
  • @AlexB.: There are equivalents to simple #define constants, but not #define macros. Commented Sep 29, 2016 at 14:46
  • Dear Reza Aghaei, thanks for pointing this out. I'm still new here (read allot) i will keep it in mind for my next post :-) Commented Oct 3, 2016 at 12:26

2 Answers 2

1

The VB equivalent is:

Public Enum ID
 PARAM_Start
 PARAM_END=PARAM_Start+255
End Enum

Not 255 values as you stated, but just 2.

Sign up to request clarification or add additional context in comments.

Comments

0

As mentioned in comments, I think your C++ will create only 2...

Could you use a T4 Text Template?:

Add TextTemplate.tt to your VB project and fill it with this code:

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System" #>
<#@ output extension=".vb" #>

Namespace MyNamespace

    Public Enum MyEnum
    <# 
    for (int i = 1; i < 256; i++)
    {
    #>
    Number<#= i #> = <#= i #>
    <# } #>
    End Enum

End Namespace

Build your solution and it'll generate the type for you.

2 Comments

@ Gill Bates, i think you're right. Didn't notice it. Still i don't quite understand wat the meaning/goal is? Is it to declare a enum with two subvalues that can be 0 to 255? @ Brandon, Thanks for the snippet, i will read the MSDN doc and try it.
The link is only there for reference. You can just copy the code into a .tt file and build your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.