problem concatenating two strings to create an enum value

Posted on 2008-11-18
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?
Question by:scm0sml
    LVL 53

    Expert Comment

    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)

    Author Comment

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

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

    Accepted Solution

    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
    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

    Author Comment

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

    worked a treat.

    thanks for that!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now