Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 4th, 2003, 03:33 PM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using Enum Type

I have Enum Type defined as followes:

Public Enum GenderType
    Male = 0
    Female = 1
End Enum

1)I am using following code to get Gender as input from user. If user entered 0 or 1 then program accepts but if user entered Male or Female it gives problem ? how the following code could be altered to work the way it accepts Male or Female as input.

        Dim PromptForGender as GenderType
        Console.Write("Please enter your gender: ")
        PromptForGender = Console.ReadLine

2)The other problem is when I tried to print from the object this gender type like contacts.GenderType it print 0 or 1 as it stored there. How I can show Male or Female instead of 0 or 1.

Help would be appreciated.

Thanks,
Reply With Quote
  #2 (permalink)  
Old June 4th, 2003, 06:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Wien, Wien, Austria.
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

You can use only ToString() method to display Enum value instaed of integer. Some example:

Public Enum GenderType
      Male = 0
      Female = 1
End Enum

Dim gt As GenderType
gt=1
Console.WriteLine(gt.ToString())

On console will be displayed Female

HTH.

Reg,
NotNowJohn

...but the Soon is eclipsed by the Moon
Reply With Quote
  #3 (permalink)  
Old June 5th, 2003, 05:20 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think you can use:

Public Enum GenderType as string
    Male = "male"
    Female = "Female"
End Enum

Quote:
quote:Originally posted by Mike2000
 I have Enum Type defined as followes:

Public Enum GenderType
    Male = 0
    Female = 1
End Enum

1)I am using following code to get Gender as input from user. If user entered 0 or 1 then program accepts but if user entered Male or Female it gives problem ? how the following code could be altered to work the way it accepts Male or Female as input.

        Dim PromptForGender as GenderType
        Console.Write("Please enter your gender: ")
        PromptForGender = Console.ReadLine

2)The other problem is when I tried to print from the object this gender type like contacts.GenderType it print 0 or 1 as it stored there. How I can show Male or Female instead of 0 or 1.

Help would be appreciated.

Thanks,
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
enum 2 names OneQuestion General .NET 4 January 2nd, 2008 02:50 PM
Enum gets initalized to first value mhshpk ASP.NET 2.0 Professional 2 September 4th, 2007 10:16 AM
enum toString() overloading kramis8 C# 0 November 21st, 2004 07:55 PM
Enum in VB saeta119 BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 June 7th, 2003 04:10 PM



All times are GMT -4. The time now is 10:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.