Passing Date Functions as variables

  • Thread starter Thread starter IntraRELY
  • Start date Start date
I

IntraRELY

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
 
* "IntraRELY said:
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.
 
IntraRELY said:
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
 
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: (e-mail address removed) (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: <[email protected]>
References: <[email protected]>
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])
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#^d
User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp (Windows)) Hamster/2.0.0.1
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.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-mail
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:158753
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

* "IntraRELY said:
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.
 
Back
Top