Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

Passing Enumerator as Parameter - (ByVal myEnum AS ????)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gene Berger - 08 Mar 2008 12:15 GMT
(See <--????? below in Sub Load_Enum for problem).

I have looked and looked ... everyone speaks about
how to use enumerators (thanks) but WHAT TYPE is
it when passing as a parameter?  

p_enm As System.Enum doesn't work.
p_enm As Object      doesn't work.
p_enm As Type        doesn't work.

Don't laugh please - I have tried stuff like:
Dim enm As System.Enum = CType(p_enm, System.Enum)

So what does work? (See <--????? below).

 Public Enum enm_cboTest1 As Integer
   Completed = 1
   Not_Started = 2
 End Enum

 Public Enum cboTest2 As Integer
   Completed = 1
   Not_Started = 2
 End Enum

 Call Load_Enum(enm_cboTest1)
 Call Load_Enum(cboTest2 As Integer)

 Private Sub Load_Enum(ByVal p_enm As System.Enum) <--?????
   Dim names As String() = System.Enum.GetNames(GetType(p_enm))
   For i As Integer = 0 To names.Length - 1
     Dim myText As String = names(i).Trim.Replace("_", " ")
     Dim myValue As p_enm = System.Enum.Parse(GetType(p_enm), names(i))
     Dim b1 As Integer = 0
   Next
 End Sub
Martin H. - 08 Mar 2008 12:54 GMT
Hello Gene,

Private Sub Load_Enum(ByVal p_enm As enm_cboTest1)
...
End Sub

Call Load_Enum(ByVal value As enm_cboTest1)

Best regards,

Martin

> (See <--????? below in Sub Load_Enum for problem).
>
[quoted text clipped - 31 lines]
>    Next
>  End Sub
Stephany Young - 08 Mar 2008 12:55 GMT
The type you need to pass is System.Type.

 Private Sub Load_Enum(ByVal type As Type)

   Dim names As String() = [Enum].GetNames(type)

   For i As Integer = 0 To names.Length - 1
     Dim myText As String = names(i).Trim.Replace("_", " ")
     Dim myValue As Object = [Enum].Parse(type, names(i))
     Dim b1 As Integer = 0
   Next

 End Sub

 Call Load_Enum(GetType(enm_cboTest1))

 Call Load_Enum(GetType(cboTest2))

Note that myValue needs to be declared as System.Object.

> (See <--????? below in Sub Load_Enum for problem).
>
[quoted text clipped - 31 lines]
>    Next
>  End Sub
Gene Berger - 08 Mar 2008 17:58 GMT
That did it ... THANKS!!!

> (See <--????? below in Sub Load_Enum for problem).
>
[quoted text clipped - 31 lines]
>    Next
>  End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.