Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

problem concatenating two strings to create an enum value

Posted on 2008-11-18
4
Medium Priority
?
358 Views
Last Modified: 2012-08-14
I have the following enum:
 Public Enum enmAvailabilityMonths              
        October08 = 1
        November08 = 2
        December08 = 3
        January09 = 4
        February09 = 5
        March09 = 6
        April09 = 7
        May09 = 8
        June09 = 9
        July09 = 10
        August09 = 11
        September09 = 12
    End Enum

In one of my functions which expects this enum i am trying to concatenate two strings to produce say the value October08 like so:

Dim month As String = GetFullMonthValue(e.Day.Date.Month)
        Dim year As String = e.Day.Date.Year.ToString.Substring(2, 2)

        RenderDay(e, CType(month & year, UKCaravanFinderUtils.enmAvailabilityMonths), cldDisplay, e.Day.Date.Year, e.Day.Date.Month)

I then try converting the value to type UKCaravanFinderUtils.enmAvailabilityMonths.

I am getting the error cannot convert my string to integer based on this value.

Is there a workaround?
0
Comment
Question by:scm0sml
  • 2
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22983080
Can you try this:

Dim myDate as enmAvailabilityMonths = (enmAvailabilityMonths )(month & year)
RenderDay(e, CType(myDate, UKCaravanFinderUtils.enmAvailabilityMonths), cldDisplay, e.Day.Date.Year, e.Day.Date.Month)
0
 

Author Comment

by:scm0sml
ID: 22985287
doesnt like this line:
Dim myDate As enmAvailabilityMonths = (enmAvailabilityMonths)(month & year)

(enmAvailabilityMonths)  is a type and cannot be used as an expression?
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 22985447
The solution you need is to convert your string to an enum-value through casting. Perhaps with the previous post I'v posted c# code (combined with vb.net).
Can you try this cast
Dim myDate  As enmAvailabilityMonths= DirectCast([Enum].Parse(GetType(enmAvailabilityMonths), Montth & Year,True), enmAvailabilityMonths)

Otherwise check the following
dim myDate as string = Month & Year
--> what is the value of myDate ? Make sure that its like your enumvalue
0
 

Author Comment

by:scm0sml
ID: 22985611
Dim myDate As enmAvailabilityMonths = DirectCast([Enum].Parse(GetType(enmAvailabilityMonths), month & year, True), enmAvailabilityMonths)

worked a treat.

thanks for that!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question