By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Passing Date Functions as variables

P: n/a
I have the following function, Notice how I am passing the dateInterval as a
string. What is the correct way to pass "DateInterval.Year" as a variable to
a function?

TIA,

Steve Wofford
www.IntraRELY.com
Private Function calc_couponPeriod(ByVal DateInterval As Integer, ByVal
installmentBeginDate As Date, ByVal installment As Date)
Return installmentFutureDate = DateAdd(dateInterval, installment,
installmentBeginDate)
End Function

Private Sub btnRates_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRates.Click
Dim installmentBeginDate = tbSettlementDate.Text
Dim dateInterval = "DateInterval.Year"
Dim principal = "1000"
Dim accruedInterest = 0
accruedInterestToDate = calc_couponPeriod(DateInterval,
installmentBeginDate, principal, accruedInterestToDate)
End Sub
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* "IntraRELY" <In*******@yahoo.com> scripsit:
I have the following function, Notice how I am passing the dateInterval as a
string. What is the correct way to pass "DateInterval.Year" as a variable to
a function?


What do you mean by "pass as a variable"? You can declare the first
parameter as 'DateInterval':

\\\
.... CalcCouponPeriod(ByVal di As DateInterval, ....)
///

Then you can pass 'DateInterval.Year' directly.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
"IntraRELY" <In*******@yahoo.com> wrote...
I have the following function, Notice how I am passing the dateInterval as a string. What is the correct way to pass "DateInterval.Year" as a variable to a function? Private Function calc_couponPeriod(ByVal DateInterval As Integer, ByVal
installmentBeginDate As Date, ByVal installment As Date)
Return installmentFutureDate = DateAdd(dateInterval, installment,
installmentBeginDate)
End Function

Private Sub btnRates_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRates.Click
Dim installmentBeginDate = tbSettlementDate.Text
Dim dateInterval = "DateInterval.Year"
Dim principal = "1000"
Dim accruedInterest = 0
accruedInterestToDate = calc_couponPeriod(DateInterval,
installmentBeginDate, principal, accruedInterestToDate)
End Sub


Steve... something is up. Turn "Strict On" in your project options. Look
at your Dim statements you haven't declared their type. That's not good.
Plus you're assigning principal as a string, that can't be right. And your
function wants 3 parameters and you're passing 4... and... I guess I had
better stop there.

Your function is expecting the DateInterval parameter to be an Integer, you
can see that, but then why would you set it to be a string?

It also looks like you've defined accruedInterest (no type) assigned it a
value of zero and did nothing with it. Time to slow down, take a breath and
think the entire process through.

Tom
Nov 20 '05 #3

P: n/a
Expanding a bit on the solution:

DateInterval is an enum, what you need to do is create a variable of the
enum's type and pass the enum's value into the function's parameter.
Here's your example modified to use the enum's type.

Private Function calc_couponPeriod(ByVal Interval As DateInterval,
ByVal installmentBeginDate As Date, ByVal installmentPeriod As Integer) As
Date
Return installmentFutureDate = DateAdd(Interval, installment,
installmentBeginDate)

End Function

Private Sub btnRates_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRates.Click

' Leave the installmentBeginDate as a date type - don't use the text
property
Dim installmentBeginDate = tbsettlementdate
Dim Interval As DateInterval =
Microsoft.VisualBasic.DateInterval.Year
Dim principal = "1000"
Dim accruedInterest = 0
'Changed to reflect adding an interval to the date - update it as
appropriate.
accruedInterestToDate = calc_couponPeriod(Interval,
installmentBeginDate, InstallmentPeriod)
End Sub

Check out the strong typing to get more info.
--------------------
From: hi***************@gmx.at (Herfried K. Wagner [MVP])
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: Re: Passing Date Functions as variables
Date: 24 Nov 2003 20:44:54 +0100
Lines: 17
Sender: Administrator@FAMILIE-IF1R60H
Message-ID: <bp*************@ID-208219.news.uni-berlin.de>
References: <e9*************@TK2MSFTNGP11.phx.gbl>
NNTP-Posting-Host: v208-105.vps.tuwien.ac.at (128.131.208.105)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de 1069703187 62565350 128.131.208.105 (16 [208219])X-Face: vJn^g[Lkg9YfJ,Oj#{Y[')WBo<1kS#Rc3Vb!D;jf$;OZ%<"'z+DX"K/m)h\Gi;e-AYsc%'CmL~Ix
@YEq$}A>^]KbF1.Z|=/'*CcB[f+8(m&vP.u4+P.q$n]?[s>nnFu/8EuC?h[c\#wR{ok_um~57to=
P=1"{qO1e%A2~nS?<[o`jn?C/-}7Mbz~L)WI=5VL!*xU#^dUser-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp (Windows)) Hamster/2.0.0.1Path: cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!f
u-berlin.de!uni-berlin.de!v208-105.vps.tuwien.ac.AT!not-for-mailXref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:158753
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

* "IntraRELY" <In*******@yahoo.com> scripsit:
I have the following function, Notice how I am passing the dateInterval as a string. What is the correct way to pass "DateInterval.Year" as a variable to a function?


What do you mean by "pass as a variable"? You can declare the first
parameter as 'DateInterval':

\\\
... CalcCouponPeriod(ByVal di As DateInterval, ....)
///

Then you can pass 'DateInterval.Year' directly.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.