473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Can this be done in VB.NET?

If this (below) is something that can be done in VB.NET can you provide an
example, link to page explaining, or at least a keyword I can use to search
Google?

What I want to do is define a group of constants so that when something
calls my function, instead of remembering what 1,2,3, and 4 is, I can call
it using the group I already defined. For instance:
Const Group Definitions:
CanTypes
1 - RegularCola
2 - DietCola
3 - CaffeneFreeCola
4 - CaffeneFreeDietCola

Example Function:
Function GetPopDetails(CanType as CanTypes) as String
if CanType = 1 then
'Do stuff
'Return info
end if
End Function

Calling Function:
dim myString as string = GetPopDetails(CanTypes.RegulaCola)
Jun 27 '08 #1
6 866
On 2008-05-21, Bishop <no****@nospam.comwrote:
If this (below) is something that can be done in VB.NET can you provide an
example, link to page explaining, or at least a keyword I can use to search
Google?

What I want to do is define a group of constants so that when something
calls my function, instead of remembering what 1,2,3, and 4 is, I can call
it using the group I already defined. For instance:
Const Group Definitions:
CanTypes
1 - RegularCola
2 - DietCola
3 - CaffeneFreeCola
4 - CaffeneFreeDietCola

Example Function:
Function GetPopDetails(CanType as CanTypes) as String
if CanType = 1 then
'Do stuff
'Return info
end if
End Function

Calling Function:
dim myString as string = GetPopDetails(CanTypes.RegulaCola)

Public Enum CanType
RegularCola
DietCola
CaffeineFreeCola
CaffeineFreeDietCola
End Enum

Function GetPopDetails (ByVal can As CanType) As String
Select can
Case CanType.RegularCola
'Do Stuff
Return Info
....
End Select
End Function

dim canInfo As String = GetPopDetails(CanTypes.RegularCola)
--
Tom Shelton
Jun 27 '08 #2
Exactly what I was looking for, thanks!

"Tom Shelton" <to*********@YOUKNOWTHEDRILLcomcast.netwrote in message
news:OL**************@TK2MSFTNGP06.phx.gbl...
On 2008-05-21, Bishop <no****@nospam.comwrote:
>If this (below) is something that can be done in VB.NET can you provide
an
example, link to page explaining, or at least a keyword I can use to
search
Google?

What I want to do is define a group of constants so that when something
calls my function, instead of remembering what 1,2,3, and 4 is, I can
call
it using the group I already defined. For instance:
Const Group Definitions:
CanTypes
1 - RegularCola
2 - DietCola
3 - CaffeneFreeCola
4 - CaffeneFreeDietCola

Example Function:
Function GetPopDetails(CanType as CanTypes) as String
if CanType = 1 then
'Do stuff
'Return info
end if
End Function

Calling Function:
dim myString as string = GetPopDetails(CanTypes.RegulaCola)


Public Enum CanType
RegularCola
DietCola
CaffeineFreeCola
CaffeineFreeDietCola
End Enum

Function GetPopDetails (ByVal can As CanType) As String
Select can
Case CanType.RegularCola
'Do Stuff
Return Info
....
End Select
End Function

dim canInfo As String = GetPopDetails(CanTypes.RegularCola)
--
Tom Shelton

Jun 27 '08 #3
"Tom Shelton" <to*********@YOUKNOWTHEDRILLcomcast.netwrote in message
news:OL**************@TK2MSFTNGP06.phx.gbl...
On 2008-05-21, Bishop <no****@nospam.comwrote:
>If this (below) is something that can be done in VB.NET can you provide
an
example, link to page explaining, or at least a keyword I can use to
search
Google?

What I want to do is define a group of constants so that when something
calls my function, instead of remembering what 1,2,3, and 4 is, I can
call
it using the group I already defined. For instance:
Const Group Definitions:
CanTypes
1 - RegularCola
2 - DietCola
3 - CaffeneFreeCola
4 - CaffeneFreeDietCola

Example Function:
Function GetPopDetails(CanType as CanTypes) as String
if CanType = 1 then
'Do stuff
'Return info
end if
End Function

Calling Function:
dim myString as string = GetPopDetails(CanTypes.RegulaCola)


Public Enum CanType
RegularCola
DietCola
CaffeineFreeCola
CaffeineFreeDietCola
End Enum

Function GetPopDetails (ByVal can As CanType) As String
Select can
Case CanType.RegularCola
'Do Stuff
Return Info
....
End Select
End Function

dim canInfo As String = GetPopDetails(CanTypes.RegularCola)
--
Tom Shelton

Because of the way VB handles "Nothing" as an enumerated value, I always
make my first enumeration item "= 1"

Public Enum CanType
RegularCola = 1
DietCola
CaffieneFreeCola
CaffeineFreeDietCola
End Enum

Defining the Enum CanType this way allows you to test for non-initialized
enumerators by testing against Nothing.

Mike Ober.
Jun 27 '08 #4
"Michael D. Ober" <obermd.@.alum.mit.edu.nospam.schrieb
>

Because of the way VB handles "Nothing" as an enumerated value, I
always make my first enumeration item "= 1"

Public Enum CanType
RegularCola = 1
DietCola
CaffieneFreeCola
CaffeineFreeDietCola
End Enum

Defining the Enum CanType this way allows you to test for
non-initialized enumerators by testing against Nothing.

Mike Ober.
As an Enum is a value type, there are no uninitialized values. Only if
you have a Nullable(Of) it makes sense.
I would never use the type with Nothing because that would support VB's
concept of handling Nothing with value types, which I don't do.

Instead, I'd add a "None" value in the Enum, if that's a valid state.
Armin

Jun 27 '08 #5
"Armin Zingler" <az*******@freenet.dewrote in message
news:uy****************@TK2MSFTNGP06.phx.gbl...
"Michael D. Ober" <obermd.@.alum.mit.edu.nospam.schrieb
>>

Because of the way VB handles "Nothing" as an enumerated value, I
always make my first enumeration item "= 1"

Public Enum CanType
RegularCola = 1
DietCola
CaffieneFreeCola
CaffeineFreeDietCola
End Enum

Defining the Enum CanType this way allows you to test for
non-initialized enumerators by testing against Nothing.

Mike Ober.

As an Enum is a value type, there are no uninitialized values. Only if you
have a Nullable(Of) it makes sense.
I would never use the type with Nothing because that would support VB's
concept of handling Nothing with value types, which I don't do.

Instead, I'd add a "None" value in the Enum, if that's a valid state.
Armin
Armin, that's what I thought also until I had a piece of code do the
following

if <enumvar= Nothing then
do "not initialized"
elseif <enumvar= <firstoption>
do "first option processing"
....
end if

The <firstoptionpath in the code never ran, so I took a deeper look at
what was going on and discovered that an uninitialized enum value is zero.
The problem is that Nothing always evaluates to zero, either as a pointer
for object types or as an number for value types.

Mike.
Jun 27 '08 #6
Here is a neat little trick I came accross...

Public Class DaysOfWeek
Public Enum DoW
Sun
Mon
Tue
Wed
Thu
Fri
Sat
End Enum

Private Shared Days As Type = GetType(DoW)
Public Shared ReadOnly Names() As String = [Enum].GetNames(Days)

Shared Sub New()
'change any of the names you want here
Names(DoW.Sun) = "Sunday"
Names(DoW.Sat) = "Saturday"
End Sub

Shared Property Item(ByVal Index As DoW) As String
Get
Return Names(Index)
End Get
Set(ByVal value As String)
Names(Index) = value
End Set
End Property

End Class

--
Terry
"Bishop" wrote:
If this (below) is something that can be done in VB.NET can you provide an
example, link to page explaining, or at least a keyword I can use to search
Google?

What I want to do is define a group of constants so that when something
calls my function, instead of remembering what 1,2,3, and 4 is, I can call
it using the group I already defined. For instance:
Const Group Definitions:
CanTypes
1 - RegularCola
2 - DietCola
3 - CaffeneFreeCola
4 - CaffeneFreeDietCola

Example Function:
Function GetPopDetails(CanType as CanTypes) as String
if CanType = 1 then
'Do stuff
'Return info
end if
End Function

Calling Function:
dim myString as string = GetPopDetails(CanTypes.RegulaCola)
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: itsharkopath | last post by:
Hi, Imagine a user in a hotspot, when he comes to the hotspot and tries to load a webpage (on the internet), he would automatically redirected to login page. I believe the following is to be...
9
by: Steven T. Hatton | last post by:
This was written for the gnu.g++.help list. It rather clearly spells out the most important feature of Java that I believe C++ lacks. I really don't believe the C++ Standard sepcifies enough for a...
16
by: jaialai technology | last post by:
I want to reload a url in a browser window so I do something like this: open(window.location.href= "www.yahoo.com"); ok, so now I want to do something when that page is done loading completely....
5
by: Morten Overgaard | last post by:
Hi I have a C# component which fires events. I want to catch these events in my MFC app compiled with the /clr. I know I can define a managed class in my MFC app which traps the events - but I...
11
by: Sharon | last post by:
I'm writing a new control derived from UserControl. I need to get an event when the control is done resizing. I tried the Resize, SizeChanged, Move and the Layout events and I also tried to...
3
by: Miguel Dias Moura | last post by:
Hi, When I subscribe a web site I usually receive an email to confirm my subscription. Only after I follow the link in the email my account gets activated. In general, how is this done? Can...
4
by: BrianDH | last post by:
Group Early this week I ask for examples on how to call a VB.NET Web Service and access its DataSet for a traditional ASP page. I was told, "you can't", "won't work", "not possible". Well I...
12
by: Ark | last post by:
Hello NG, I arrange data in structs like { members... uint16_t crc; more members, maybe... } Then I need to save them, up to and including crc, in non-volatile memory or a file, as the case...
2
by: maya | last post by:
http://news.yahoo.com/news?tmpl=index2&cid=703 down the page, under "More Stories", there's a section with two interchangeable divs which slide back and forth into view.. how is this done? I...
2
by: poolboi | last post by:
hey guys, i've done most of my web app. for searching almost done but then i got a small little problem with logging in i need to know how session tracking is done in perl if not my log in page...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.