469,929 Members | 1,386 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

Default NULL parameter

Hi,

I am using vb.net and I would like to define one of my function parameters
to have a default value of null (in this case an sqltranaction object)

however I am having a great deal of trouble doing this.

my (incorrect) function declaration is below and I would appreciate somebody
pointing out my error.

Public Function EnterPractice(ByVal strPracticeName As String, ByVal
strUserName As String, ByVal objTran As SqlTransaction = dbnull) As Integer
Also, how would I explicitly pass a null argument to the function.

many thnaks in advance.

martin.
Nov 18 '05 #1
3 1462
Try this:
Public Function EnterPractice(ByVal strPracticeName As String, ByVal
strUserName As String, Optional ByVal objTran As SqlTransaction = Nothing)
As Integer

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"martin" <St**************@yahoo.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
Hi,

I am using vb.net and I would like to define one of my function parameters
to have a default value of null (in this case an sqltranaction object)

however I am having a great deal of trouble doing this.

my (incorrect) function declaration is below and I would appreciate somebody pointing out my error.

Public Function EnterPractice(ByVal strPracticeName As String, ByVal
strUserName As String, ByVal objTran As SqlTransaction = dbnull) As Integer

Also, how would I explicitly pass a null argument to the function.

many thnaks in advance.

martin.

Nov 18 '05 #2

"martin" <St**************@yahoo.com> wrote in message news:uQ*************@TK2MSFTNGP10.phx.gbl...
Hi,

I am using vb.net and I would like to define one of my function parameters
to have a default value of null (in this case an sqltranaction object)

however I am having a great deal of trouble doing this.

my (incorrect) function declaration is below and I would appreciate somebody
pointing out my error.

Public Function EnterPractice(ByVal strPracticeName As String, ByVal
strUserName As String, ByVal objTran As SqlTransaction = dbnull) As Integer

I have no experience with vb.net, but I guess you need "DBNull.Value" here.
(DBNull is the class, DBNull.Value is an ("the") instance)
Also, how would I explicitly pass a null argument to the function.

Just write "null" as the argument (by the way: "null" is NOT equal to "DBNull.Value")

Integer res = EnterPractice("thePracticeName", "theUserName", null)

(or should the C# "null" be translated in vb as "Nothing" ??)
many thnaks in advance.

martin.

Nov 18 '05 #3
Thanks guys

cheers

martin
"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...

"martin" <St**************@yahoo.com> wrote in message news:uQ*************@TK2MSFTNGP10.phx.gbl...
Hi,

I am using vb.net and I would like to define one of my function parameters to have a default value of null (in this case an sqltranaction object)

however I am having a great deal of trouble doing this.

my (incorrect) function declaration is below and I would appreciate somebody pointing out my error.

Public Function EnterPractice(ByVal strPracticeName As String, ByVal
strUserName As String, ByVal objTran As SqlTransaction = dbnull) As Integer


I have no experience with vb.net, but I guess you need "DBNull.Value"

here. (DBNull is the class, DBNull.Value is an ("the") instance)

Also, how would I explicitly pass a null argument to the function.

Just write "null" as the argument (by the way: "null" is NOT equal to

"DBNull.Value")
Integer res = EnterPractice("thePracticeName", "theUserName", null)

(or should the C# "null" be translated in vb as "Nothing" ??)
many thnaks in advance.

martin.


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Senthilvel | last post: by
2 posts views Thread by The Plankmeister | last post: by
5 posts views Thread by asianmuscle | last post: by
16 posts views Thread by jryden | last post: by
3 posts views Thread by Gary Wessle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.