-
Feb 27th, 2015, 09:49 AM
#1
Thread Starter
New Member
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
-
Feb 27th, 2015, 10:00 AM
#2
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
-
Feb 27th, 2015, 10:51 AM
#3
Thread Starter
New Member
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?
-
Feb 27th, 2015, 11:05 AM
#4
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
-
Feb 27th, 2015, 11:09 AM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|