Does anyone know what parameter should be used instead of Date = 0 for the
optional parameter in the following function?
Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date =
0) As Short 10 11872
"John Morgan" <j.******@premsoftware.com> schrieb Does anyone know what parameter should be used instead of Date = 0 for the optional parameter in the following function?
Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date = 0) As Short
Which date should be the default value when dtmDate is not passed? Zero is
not a date.
You might also consider writing an overloaded version instead.
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date =
0) As Short
Dim intAge As Short
If dtmDate = System.DateTime.FromOADate(0) Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Today
End If
intAge = DateDiff(Microsoft.VisualBasic.DateInterval.Year, dtmBD, dtmDate)
If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), Day(dtmBD)) Then
intAge = intAge - 1
End If
dhAge = intAge
Return dhAge
End Function
--- This works as is in vb6
"Armin Zingler" <az*******@freenet.de> wrote in message
news:#$**************@tk2msftngp13.phx.gbl... "John Morgan" <j.******@premsoftware.com> schrieb Does anyone know what parameter should be used instead of Date = 0 for the optional parameter in the following function?
Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date = 0) As Short
Which date should be the default value when dtmDate is not passed? Zero is not a date.
You might also consider writing an overloaded version instead.
-- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"John Morgan" <j.******@premsoftware.com> schrieb Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date = 0) As Short
Dim intAge As Short
If dtmDate = System.DateTime.FromOADate(0) Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Today
End If
intAge = DateDiff(Microsoft.VisualBasic.DateInterval.Year, dtmBD, dtmDate)
If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), Day(dtmBD)) Then
intAge = intAge - 1
End If
dhAge = intAge
Return dhAge
End Function --- This works as is in vb6
What's your question?
My question is still: Which date do you expect to be passed whenever you
don't pass the second argument?
Maybe you are looking for this (untested):
Public Function dhAge(ByVal dtmBD As Date) As Short
Return dhAge(dtmBD, Date.Today)
End Function
Public Function dhAge( _
ByVal dtmBD As Date, _
ByVal dtmDate As Date) As Short
Dim intAge As Short
intAge = DateDiff(DateInterval.Year, dtmBD, dtmDate)
If dtmDate < New Date(dtmDate.Year, dtmBD.Month, dtmBD.Day) Then
intAge -= 1
End If
Return intAge
End Function
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
The first thing your function does is check whether dtmDate was input by the
user and set it to Todays Date if it is not. Therefore, instead of the
optional parameter being 0 it should be Date.Today. However, this is not
valid as it is not a constant. You are now programming in VB.Net not VB6 and
so you should not expect all your VB6 code to work as it did. Instead of
adding Optional parameters you simply create multiple functions with
different parameters. This is what Armin suggested, it is called
Overloading.
The VB.Net translation of your VB6 code follows:
Public Function dhAge(ByVal dtmBD As Date) As Short
Return dhAge(dtmBD, Date.Today)
End Function
Public Function dhAge(ByVal dtmBD As Date, ByVal dtmDate As Date) As Short
Dim shAge As Short _
= CShort(DateDiff(DateInterval.Year, dtmBD, dtmDate))
If dtmDate < DateSerial(dtmDate.Year, dtmBD.Month, dtmBD.Day) Then
shAge -= CShort(1)
End If
Return shAge
End Function
"John Morgan" <j.******@premsoftware.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl... Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date
= 0) As Short
Dim intAge As Short
If dtmDate = System.DateTime.FromOADate(0) Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Today
End If
intAge = DateDiff(Microsoft.VisualBasic.DateInterval.Year, dtmBD, dtmDate)
If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), Day(dtmBD)) Then
intAge = intAge - 1
End If
dhAge = intAge
Return dhAge
End Function --- This works as is in vb6
"Armin Zingler" <az*******@freenet.de> wrote in message news:#$**************@tk2msftngp13.phx.gbl... "John Morgan" <j.******@premsoftware.com> schrieb Does anyone know what parameter should be used instead of Date = 0 for the optional parameter in the following function?
Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date = 0) As Short
Which date should be the default value when dtmDate is not passed? Zero
is not a date.
You might also consider writing an overloaded version instead.
-- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Look at that. Great minds think alike, only some have Option Strict On. ;-)
"Armin Zingler" <az*******@freenet.de> wrote in message
news:ef**************@TK2MSFTNGP11.phx.gbl... "John Morgan" <j.******@premsoftware.com> schrieb Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date = 0) As Short
Dim intAge As Short
If dtmDate = System.DateTime.FromOADate(0) Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Today
End If
intAge = DateDiff(Microsoft.VisualBasic.DateInterval.Year, dtmBD, dtmDate)
If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), Day(dtmBD)) Then
intAge = intAge - 1
End If
dhAge = intAge
Return dhAge
End Function --- This works as is in vb6
What's your question?
My question is still: Which date do you expect to be passed whenever you don't pass the second argument?
Maybe you are looking for this (untested):
Public Function dhAge(ByVal dtmBD As Date) As Short Return dhAge(dtmBD, Date.Today) End Function
Public Function dhAge( _ ByVal dtmBD As Date, _ ByVal dtmDate As Date) As Short
Dim intAge As Short
intAge = DateDiff(DateInterval.Year, dtmBD, dtmDate)
If dtmDate < New Date(dtmDate.Year, dtmBD.Month, dtmBD.Day) Then intAge -= 1 End If
Return intAge End Function
-- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]>
schrieb Look at that. Great minds think alike, only some have Option Strict On. ;-)
*argh* It is *always* on! :-)
Unfortunatelly I tried the code in a project just upgraded by the upgrade
wizard, and there is option strict off.
Improved version: ;-)
Public Function dhAge(ByVal dtmBD As Date) As Short
Return dhAge(dtmBD, Date.Today)
End Function
Public Function dhAge( _
ByVal dtmBD As Date, _
ByVal dtmDate As Date) As Short
Dim intAge As Short
intAge = CShort(DateDiff(DateInterval.Year, dtmBD, dtmDate))
If dtmDate < New Date(dtmDate.Year, dtmBD.Month, dtmBD.Day) Then
intAge -= 1S
End If
Return intAge
End Function
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
This does not compile with Option Strict On
Use always Strict on
That Mick showed it us: greath!!!!.
I hope that Nick and Fergus see this also.
:-)))))))))))) 'and not more than that
Cor
"Cor" <no*@non.com> schrieb This does not compile with Option Strict On
Use always Strict on
I always do - blame the upgrade wizard. ;-)))
That Mick showed it us: greath!!!!.
I hope that Nick and Fergus see this also.
:-)))))))))))) 'and not more than that
Cor
Strange..... Each time I read your name I see a girl. *g*
"Hit me baby one more time"
;-))))))))
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Yes, overloading was the answer -- I had been reading about that, -- I am
trying to make a class in vb.net and process it as unmanaged code -- My
first step in converting a 300,000 line vb6 program to vb.net.
Thank's
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:e4**************@TK2MSFTNGP09.phx.gbl... The first thing your function does is check whether dtmDate was input by
the user and set it to Todays Date if it is not. Therefore, instead of the optional parameter being 0 it should be Date.Today. However, this is not valid as it is not a constant. You are now programming in VB.Net not VB6
and so you should not expect all your VB6 code to work as it did. Instead of adding Optional parameters you simply create multiple functions with different parameters. This is what Armin suggested, it is called Overloading.
The VB.Net translation of your VB6 code follows:
Public Function dhAge(ByVal dtmBD As Date) As Short Return dhAge(dtmBD, Date.Today) End Function
Public Function dhAge(ByVal dtmBD As Date, ByVal dtmDate As Date) As Short Dim shAge As Short _ = CShort(DateDiff(DateInterval.Year, dtmBD, dtmDate)) If dtmDate < DateSerial(dtmDate.Year, dtmBD.Month, dtmBD.Day) Then shAge -= CShort(1) End If Return shAge End Function
"John Morgan" <j.******@premsoftware.com> wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl... Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As
Date = 0) As Short
Dim intAge As Short
If dtmDate = System.DateTime.FromOADate(0) Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Today
End If
intAge = DateDiff(Microsoft.VisualBasic.DateInterval.Year, dtmBD,
dtmDate) If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), Day(dtmBD)) Then
intAge = intAge - 1
End If
dhAge = intAge
Return dhAge
End Function --- This works as is in vb6
"Armin Zingler" <az*******@freenet.de> wrote in message news:#$**************@tk2msftngp13.phx.gbl... "John Morgan" <j.******@premsoftware.com> schrieb > Does anyone know what parameter should be used instead of Date = 0 > for the optional parameter in the following function? > > Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As > Date = 0) As Short
Which date should be the default value when dtmDate is not passed?
Zero is not a date.
You might also consider writing an overloaded version instead.
-- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Sounds like you've got a lot of re-learning to do. I remember when I first
leapt from VB6 to .net, back in January this year, I thought I was never
going to get the hang of it. However after about 3 weeks I was almost as
confident in .net as I was in VB6. That said there is still a lot for me to
learn.
Have fun, and any questions just ask.
Mick Doherty
"John Morgan" <j.******@premsoftware.com> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl... Yes, overloading was the answer -- I had been reading about that, -- I am trying to make a class in vb.net and process it as unmanaged code -- My first step in converting a 300,000 line vb6 program to vb.net. Thank's "Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote
in message news:e4**************@TK2MSFTNGP09.phx.gbl... The first thing your function does is check whether dtmDate was input by the user and set it to Todays Date if it is not. Therefore, instead of the optional parameter being 0 it should be Date.Today. However, this is not valid as it is not a constant. You are now programming in VB.Net not VB6 and so you should not expect all your VB6 code to work as it did. Instead of adding Optional parameters you simply create multiple functions with different parameters. This is what Armin suggested, it is called Overloading.
The VB.Net translation of your VB6 code follows:
Public Function dhAge(ByVal dtmBD As Date) As Short Return dhAge(dtmBD, Date.Today) End Function
Public Function dhAge(ByVal dtmBD As Date, ByVal dtmDate As Date) As
Short Dim shAge As Short _ = CShort(DateDiff(DateInterval.Year, dtmBD, dtmDate)) If dtmDate < DateSerial(dtmDate.Year, dtmBD.Month, dtmBD.Day) Then shAge -= CShort(1) End If Return shAge End Function
"John Morgan" <j.******@premsoftware.com> wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl... Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date = 0) As Short
Dim intAge As Short
If dtmDate = System.DateTime.FromOADate(0) Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Today
End If
intAge = DateDiff(Microsoft.VisualBasic.DateInterval.Year, dtmBD, dtmDate) If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), Day(dtmBD)) Then
intAge = intAge - 1
End If
dhAge = intAge
Return dhAge
End Function --- This works as is in vb6
"Armin Zingler" <az*******@freenet.de> wrote in message news:#$**************@tk2msftngp13.phx.gbl... > "John Morgan" <j.******@premsoftware.com> schrieb > > Does anyone know what parameter should be used instead of Date = 0 > > for the optional parameter in the following function? > > > > Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate
As > > Date = 0) As Short > > Which date should be the default value when dtmDate is not passed?
Zero is > not a date. > > You might also consider writing an overloaded version instead. > > > -- > Armin > > http://www.plig.net/nnq/nquote.html > http://www.netmeister.org/news/learn2quote.html >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JT |
last post by:
how can i declare a function that will accept an optional parameter?
something like:
function newFunc(strValue1, strValue2) --where strValue2 is optional.
thanks much.
|
by: Darryl Kerkeslager |
last post by:
Here's the function:
Public Function SaveToServer(tableName As String, prefix As String, _
changed As Date, Optional
recordID As Variant)
As Boolean
and here's the function call that doesn't...
|
by: MLH |
last post by:
The following function declaration confuses me...
Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef
sReason As String) As Boolean
I tried pasting it and its code into an...
|
by: William Ryan |
last post by:
I just picked up a copy of John Robbins' debugging book and started to look
at disassembled code. Anyway, I hate optional Parameters in VB, but I was
checking them out to see what IL is created. ...
|
by: Learning SQL Server |
last post by:
What should the default value for an optional Date parameter be in a
function if I want it to default to Nothing?
Setting the optional value to "" fails, so does setting it to Nothing.
...
|
by: John Austin |
last post by:
I am migrating my first vb6 app to vb.net 2003.
In the vb6 app a number of subs had optional date parameters:
Sub Fred ( ... ,optional FromDate as Date = 0...)
I need something like zero in...
|
by: Oenone |
last post by:
In our applications, we use the special value of DateTime.MinValue to
represent "null dates" throughout all our code. We recently ran into an
issue where we wanted an optional date parameter for a...
|
by: pamelafluente |
last post by:
Hi guys,
In the past I have used several time optional parameters in my
function.
But Now I am more inclined to think that they are more dangerous than
useful, and probably better to be...
|
by: jamesclose |
last post by:
My problem is this (apologies if this is a little long ... hang in there):
I can define a function in VB.NET with optional parameters that wraps a SQL procedure:
Sub Test(Optional ByVal Arg1...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |