Results 1 to 5 of 5

Thread: From VBA to VB.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    3

    From VBA to VB.NET

    Good morning I am trying to convert an Excel function to VB.NET. What the code is suppose to do is to count 4 years from a date excluding July and August so really (40) months. I am having trouble with this in VB.NET as I am rather new to it. Can someone please help me or guide me, it would be much appreciated! Thank you in advance.

    Code:
    Function tenure(r As Date)
    tenure = DateAdd("yyyy", 4, r)
        Select Case Month(tenure)
        Case 7, 8
            tenure = WorksheetFunction.EoMonth(tenure, 8 - Month(tenure)) + 1)
        End Select
    tenure = Format(tenure, "mm/dd/yyyy")
    End Function

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    Re: From VBA to VB.NET

    In .net use, use the Date.AddMonths method. The Date class also exposes AddSeconds, minutes, hours, years, etc.
    kevin



    Code:
    private Function tenure(thisDate as date) as Date
    
           return thisDate.AddMonths(40)
    End function
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    3

    Re: From VBA to VB.NET

    Thanks Kebo that part I understand. I have a textbox that a date is put into, if the date that is entered 48 months from now falls into July or August it must return the first day of September since July and August are exempt from the calculation. Does this make sense?

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: From VBA to VB.NET

    the words make sense... the requirement doesn't... but then we don't have context... So add 4 years to the date... then check the month portion... if it is 7 or 8 then return 9/1 of that year.

    uber simple:
    Code:
        Private Function newTenure(startDate As Date) As Date
            Dim retDate As Date = startDate.AddYears(4)
    
            If retDate.Month = 7 OrElse retDate.Month = 8 Then
                retDate = New Date(retDate.Year, 9, 1)
            End If
    
            Return retDate
        End Function
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    3

    Re: From VBA to VB.NET

    techgnome,

    That did it! I appreciate your help and guidance!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width