Connecting Tech Pros Worldwide Forums | Help | Site Map

Passing Date Functions as variables

IntraRELY
Guest
 
Posts: n/a
#1: Nov 20 '05
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



Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Passing Date Functions as variables


* "IntraRELY" <IntraRELY@yahoo.com> scripsit:[color=blue]
> 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?[/color]

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>
Tom Leylan
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Passing Date Functions as variables


"IntraRELY" <IntraRELY@yahoo.com> wrote...[color=blue]
> I have the following function, Notice how I am passing the dateInterval as[/color]
a[color=blue]
> string. What is the correct way to pass "DateInterval.Year" as a variable[/color]
to[color=blue]
> a function?[/color]
[color=blue]
> 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[/color]

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


Dot Net Team [MSFT]
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Passing Date Functions as variables


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.


--------------------[color=blue]
>From: hirf-spam-me-here@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: <bptn6j$1rlav6$6@ID-208219.news.uni-berlin.de>
>References: <e9H$26rsDHA.424@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[/color]
[208219])[color=blue]
>X-Face:[/color]
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[color=blue]
>User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp (Windows))[/color]
Hamster/2.0.0.1[color=blue]
>Path:[/color]
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-mail[color=blue]
>Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:158753
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>
>* "IntraRELY" <IntraRELY@yahoo.com> scripsit:[color=green]
>> I have the following function, Notice how I am passing the dateInterval[/color][/color]
as a[color=blue][color=green]
>> string. What is the correct way to pass "DateInterval.Year" as a[/color][/color]
variable to[color=blue][color=green]
>> a function?[/color]
>
>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>
>[/color]

Closed Thread