Hi,
I would like to know how to create variables like booleans

When you type a boolean command it look like this

Dim Boo as Boolean
Boo = True
False
and then you select one

Can this style of preset entries be done for Other Custom Variables

i.e.
Dim Height as Size
Height = Small
Medium
Large

Thanks
Peter

Dani AI

Generated

Good call by — VB.NET enums are the language feature intended for "fixed option" variables (named values with underlying integers). They give readable names, compile-time checking, and map directly to integers when storing or transmitting. See the Visual Basic documentation for enumerations for details and syntax: .

A few practical extensions and clarifications based on the thread:

  • was right that attributes let enum members carry descriptive text; the common pattern is to use a DescriptionAttribute or resource strings for display text and reflection to read those descriptions when populating UI. See the attribute docs: DescriptionAttribute.
  • For parsing and validating textual input (for example, values posted from a form), use the safe parse APIs rather than casting or fragile string comparisons. The TryParse pattern avoids exceptions and keeps code robust: Enum.TryParse.

Practical tips and cautions:

  • Use the FlagsAttribute only when members are intended to combine bitwise. For single-choice options (Small/Medium/Large) plain enums are correct. See FlagsAttribute for guidance.
  • When enums are persisted (database, serialized messages), prefer explicit numeric assignments or store the name as a string with careful versioning. Changing implicit numeric values later can break stored data or protocol compatibility.
  • Select Case works with enums (as suggested), but comparisons should use the enum values (or True/False for booleans), not raw integers; keep Option Strict On and validate inputs when converting from strings.

These pointers supplement the thread’s Enum solution and help avoid common pitfalls when using enums in ASP.NET/VB.NET applications.

Recommended Answers

All 5 Replies

I have found my own answer

'Size Options  
Public Enum Size  
     Small = 0  
     Medium = 1  
     Large = 2  
 End Enum  
  
 Dim PictureSize as Size  
 PictureSize = Small  
             Medium  
             Large  
  
 'and they return  
'   Small = 0  
'   Medium = 1  
'   Large = 2  

or else,
Try using select statements-
dim a as boolean
select a
case 0
request.write("its true")
case 1
request.write("its false")
end select
happy programming....

You can even store string values to the enum variables.

String values are possible using attributes not directly.

Using "Public Enum" looks like the best
method for setting selectable FIXED options
like SIZE(Small, Medium, Large)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.