473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing Date Functions as variables

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
3 1903
* "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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chieko Kuroda | last post by:
Hello all, I would like to learn the syntax for passing variables that I retreived from a database to a second asp page. Currently, I'm using: Response.Write "<tr><td>&nbsp;</td><td><Font size=...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
2
by: Keith | last post by:
Good Afternoon, New to .Net. I am trying to pass date/time values to a MS Access query depending on what value is selected from a dropdown list box (January, February, etc). I have declared...
1
by: Roy | last post by:
I'm assuming this is amazingly simple and I'm just missing the boat. On the html side of an asp.net page I have a datagrid, a "search" button, and 8 text boxes for search criteria. A user enters...
12
by: Dennis D. | last post by:
Hello: I want a function to return three variables to the calling procedure: Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as Integer, ByVal iAddMins as Integer) As...
1
by: Lauren Quantrell | last post by:
I already figured out (the hard way) I need to convert all my date parameters into USA format before executing my stored procedures where dates are used as parameters. (Format(StartDate, "m/d/yyyy...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.