473,503 Members | 4,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best awy to create a function?

Bob
Hi,

I defined in a class a function which inserts records into a table. There is
no return.
I defined it first like this:
Public Shared Function myfunction(ByVal param1 As Integer) As Boolean
.....
return true
end function

and then without As Boolean:
Public Shared Function myfunction(ByVal param1 As Integer)
.....
end function

But i cant' see any difference between both.
What's the best way to do: with or without As Boolean?
Thanks
Bob
Nov 12 '07 #1
8 1052
On Nov 12, 9:23 am, "Bob" <b...@no.erwrote:
Hi,

I defined in a class a function which inserts records into a table. There is
no return.
I defined it first like this:
Public Shared Function myfunction(ByVal param1 As Integer) As Boolean
....
return true
end function

and then without As Boolean:
Public Shared Function myfunction(ByVal param1 As Integer)
....
end function

But i cant' see any difference between both.
What's the best way to do: with or without As Boolean?
Thanks
Bob
First of all, before you do anything else, turn on Option Strict. IMO,
you should always have this on, unless you are working on one of the
very few scenarios where it isn't possible. With Option Strict On, you
can see your second function is not valid.

As far as which one is better, you must look at what the method needs
to do. If it needs to return a boolean value representing if the
insert was successful, it must be a boolean function. If it does not
need to return a value, you should define it as a regular method, like
the below:

////////////////
Public Shared Sub Foo(ByVal meaningfulName As Integer)

End Sub
///////////////

Thanks,

Seth Rowe

Nov 12 '07 #2

Read this:
http://blogs.msdn.com/kcwalina/archi...16/396787.aspx

which would suggest NOT using the boolean return.

And yes, put

Option Strict On
Option Explicit On

at the top of all your vb code pages.

There may also be a project or solution setting for this, but its a good
habit to get into.

...

"Bob" <bo*@no.erwrote in message
news:ec**************@TK2MSFTNGP03.phx.gbl...
Hi,

I defined in a class a function which inserts records into a table. There
is no return.
I defined it first like this:
Public Shared Function myfunction(ByVal param1 As Integer) As Boolean
....
return true
end function

and then without As Boolean:
Public Shared Function myfunction(ByVal param1 As Integer)
....
end function

But i cant' see any difference between both.
What's the best way to do: with or without As Boolean?
Thanks
Bob

Nov 12 '07 #3
There may also be a project or solution setting for this

Tools-->Options-->Projects and Solutions-->VB Defaults
>From there you can set the Option Explicit, Strict, Compare and Infer
(VS 2008) defaults.

Thanks,

Seth Rowe

Nov 12 '07 #4

Just the one caveat about this.

If you're in a multi developer environment, another use can check code out,
and have a different setting.

Aka, "environment setup wars".

And the these are the "default" values. So a preexisting project/solution
might gotcha as well.

...

But if you're a single developer, then yes, set the defaults up to make life
easier.

My opinion is that when its a multi developer environment, throwing the
lines at the top of the code is a good habit.
But its an opinion.
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@o3g2000hsb.googlegro ups.com...
>There may also be a project or solution setting for this

Tools-->Options-->Projects and Solutions-->VB Defaults
>>From there you can set the Option Explicit, Strict, Compare and Infer
(VS 2008) defaults.

Thanks,

Seth Rowe

Nov 12 '07 #5
Youch and Boooooo.

lol
I didn't know about that one.
At least you lucked out - I found out about it the hard way:

-- remembering the past --

"What the **** do you mean the web site's down?"
...
"Oh, it's says a boolean can't equal "hello, world"?"

-- nightmare fades --

I admit I made that scenario up, but it did take me a while to figure
out why a previous project was acting funny. Since then I've switched
most web apps over to C#, as it is brutal (in a good way) when it
comes to preventing those types of errors. Juan Llibre over in the
ASP.NET newsgroup posted a solution which involved modifying the
templates to include the Option lines a long time ago, but that's
still plagued by the "environment setup wars" you mentioned above.

Thanks,

Seth Rowe

Nov 12 '07 #6

Yeah, if there was some kind of

Option JustLikeCSharp On

that couldn't be turned off...then I'd been ok with VB.Net.

But after 100 times of correcting other developers (the worst I saw is when
we turned it "on" at the project level, this one developer's code generated
over 200 errors)......
you get worn down.

I code 95% in csharp now, only maintenance in vb.net....and those kind of
situations just don't happen.


"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
>Youch and Boooooo.

lol
>I didn't know about that one.

At least you lucked out - I found out about it the hard way:

-- remembering the past --

"What the **** do you mean the web site's down?"
...
"Oh, it's says a boolean can't equal "hello, world"?"

-- nightmare fades --

I admit I made that scenario up, but it did take me a while to figure
out why a previous project was acting funny. Since then I've switched
most web apps over to C#, as it is brutal (in a good way) when it
comes to preventing those types of errors. Juan Llibre over in the
ASP.NET newsgroup posted a solution which involved modifying the
templates to include the Option lines a long time ago, but that's
still plagued by the "environment setup wars" you mentioned above.

Thanks,

Seth Rowe

Nov 12 '07 #7
Yeah, if there was some kind of
>
Option JustLikeCSharp On
I actually started a thread on this a long time ago when I realized
the following difference between C# and VB.Net

//////////////
public int MyIntProperty {
get {

}
}
//////////////

Will throw the "not all code path's return a value" exception, while
it's VB equivalent:

//////////////
Public ReadOnly Property MyIntegerProperty() As Integer
Get

End Get
End Property
//////////////

Will not give any notification of a problem, it will happily return 0
(or the default value for other Value types) at runtime, often to your
program's doom. It can also be a pain to debug and fix - especially if
the missing return is in a deeply nested if or other nasty structure.
But after 100 times of correcting other developers (the worst I saw is when
we turned it "on" at the project level, this one developer's code generated
over 200 errors)......
you get worn down.
lol - I bet
I code 95% in csharp now, only maintenance in vb.net....and those kind of
situations just don't happen.
I still love to program in Visual Basic (especially for Office
interop) but I do lean towards C# for quit a few projects. If nothing
else I at least like staying sharp (pun intended) when it comes to VB.
It's just a shame that VB will allow (usually new) developers the
option to be a poor programmer. The brutal (again in a good way) error
checking of C# often makes maintenance much easier, especially when
you're looking at someone else's code.

Thanks,

Seth Rowe

Nov 12 '07 #8
"Bob" <bo*@no.erschrieb:
I defined in a class a function which inserts records into a table. There
is no return.
I defined it first like this:
Public Shared Function myfunction(ByVal param1 As Integer) As Boolean
....
return true
end function

and then without As Boolean:
Public Shared Function myfunction(ByVal param1 As Integer)
....
end function

But i cant' see any difference between both.
What's the best way to do: with or without As Boolean?
In addition to the other replies, note that the second function returns
'Object' and the function declaration is semantically equal to 'Public
Shared Function MyFunction(ByVal param1 As Integer) As Object'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 12 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
2602
by: Swartz | last post by:
Hi all. I'm working here on a small project of mine. I'm not new to programming, but I'm new to PHP. You have to understand that I'm coming from C++, OOP world, so my code might seems a little...
4
1704
by: Harald Massa | last post by:
Old, very old informatical problem: I want to "print" grouped data with head information, that is: eingabe= shall give: ( Braces are not important...) 'Stuttgart', '70197' --data--...
37
2832
by: middletree | last post by:
Yesterday, I posted a problem which, by the way, I haven't been able to solve yet. But in Aaron's reply, he questioned why I did several things the way I did. My short answer is that I have a lot...
2
1744
by: Jason Gates | last post by:
Dear all I have written a very complex web app for intranet use. It allows users to search a large database and then returns formatted results. I am currently employing a method as below: 1....
4
2118
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
15
2209
by: John J | last post by:
I've written the following code into a class to search for and display the results of all races entered (The complete code is in a previous thread). I wish to amend the code so as to display the...
2
2907
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
7
6972
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
16
2770
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
4
2878
by: =?Utf-8?B?bW9mbGFoZXJ0eQ==?= | last post by:
In VB6, we created a number of ActiveX DLLs that all shared a similar interface. The main application would load these in dynamically (late-bound.) This worked well for our situation because we...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7063
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
7258
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,...
1
6970
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...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.