Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

problem concatenating two strings to create an enum value

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?
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

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)
Avatar of scm0sml
scm0sml

ASKER

doesnt like this line:
Dim myDate As enmAvailabilityMonths = (enmAvailabilityMonths)(month & year)

(enmAvailabilityMonths)  is a type and cannot be used as an expression?
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scm0sml

ASKER

Dim myDate As enmAvailabilityMonths = DirectCast([Enum].Parse(GetType(enmAvailabilityMonths), month & year, True), enmAvailabilityMonths)

worked a treat.

thanks for that!