473,803 Members | 3,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

not all paths return a value

guy
i have inherited the following migrated vb6 code (vb2005)
but i DONT get the "not all paths return a value" squiggly - is this a
'feature' of on error goto?

Private Function CreateFolder(By Val sFileName As String) As Boolean

On Error GoTo Errors

'Create it if necessary
If Directory.Exist s(sFileName) = False Then
Directory.Creat eDirectory(sFil eName)
End If

'Succeeded in creating a folder
CreateFolder = True

Errors:

End Function
Jan 3 '06
25 2575
Looks like a normal behavior as all paths are likely returning a value as
all paths are ending with end function (and the implicit return value is
false). IMO you have rather this warning when you use the "exit function"
statement ??

--
Patrice

"guy" <gu*@discussion s.microsoft.com > a écrit dans le message de
news:5E******** *************** ***********@mic rosoft.com...
i have inherited the following migrated vb6 code (vb2005)
but i DONT get the "not all paths return a value" squiggly - is this a
'feature' of on error goto?

Private Function CreateFolder(By Val sFileName As String) As Boolean

On Error GoTo Errors

'Create it if necessary
If Directory.Exist s(sFileName) = False Then
Directory.Creat eDirectory(sFil eName)
End If

'Succeeded in creating a folder
CreateFolder = True

Errors:

End Function

Jan 3 '06 #11
A value is still returned even if not explicit so Im' not sure the warning
would be fine here. Let's take the other way round. What kind of code would
create this warning ? (Exit Function ?)

--
Patrice

"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNO SPAM> a écrit dans le message
de news:c1******** *************** *********@4ax.c om...

His point is that - on the surface - it does not *explicitly*
return a value.

/JB

On Tue, 3 Jan 2006 18:37:08 +0100, "m.posseth" <po*****@planet .nl>
wrote:

well it does return a value cause it returns false
as a boolean datatype can`t be nothing or empty

:-)

so what is the point ??

M. Posseth [MCP]
"guy" <gu*@discussion s.microsoft.com > schreef in bericht
news:7E******* *************** ************@mi crosoft.com...
this will definitely be rewritten, my point was the code as it stands does NOT warn about a code path that does not return a value

"John Timney ( MVP )" wrote:

I dont program in VB.NET - but not all paths return a value because
falling
into error before you set createFolder=Tr ue would fail to provide a
return
value, and you need to return a bool.

Put CreateFolder = False in your error section. Better still - start
using
try/catch statements and get rid of the goto
--
Regards

John Timney
Microsoft MVP

"guy" <gu*@discussion s.microsoft.com > wrote in message
news:5E******** *************** ***********@mic rosoft.com...
>i have inherited the following migrated vb6 code (vb2005)
> but i DONT get the "not all paths return a value" squiggly - is this a > 'feature' of on error goto?
>
> Private Function CreateFolder(By Val sFileName As String) As Boolean >
> On Error GoTo Errors
>
> 'Create it if necessary
> If Directory.Exist s(sFileName) = False Then
> Directory.Creat eDirectory(sFil eName)
> End If
>
> 'Succeeded in creating a folder
> CreateFolder = True
>
> Errors:
>
> End Function
>
>

Jan 3 '06 #12
"guy" <gu*@discussion s.microsoft.com > wrote in message
news:5E******** *************** ***********@mic rosoft.com...
i have inherited the following migrated vb6 code (vb2005)
but i DONT get the "not all paths return a value" squiggly - is this a
'feature' of on error goto?

Errors:

End Function


I've read a few of these answers that state something along the lines of:
Just put a "CreateFold er = False" line after the "Errors:" label.


That should never be required. Since False is the default return value for
any boolean function/variable/whatever, explicitly setting the return =
False should never be required. If it is suddenly required after 30 years of
programming, there should be a huge notice posted on the web somewhere that
says "forget about your existing source code, everything has suddenly
changed for no good reason"

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Jan 3 '06 #13
"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNO SPAM> schrieb:
To me it seems that they have forgotten to implement the check for 'On
Error
GoTo'...


As far as I understand it, the squiggly lines are not based on the
source text you see, but what the parser turns it into. Which in this
case is an entirely different beast. See my other post.


The occurance of the warning depends on the return type of the function. So
it's not actually a bug, but I believe the warning could have been
implemented in a way that it is also shown for functions which return a
value type.

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

Jan 3 '06 #14
"Patrice" <no****@nowhere .com> schrieb:
Looks like a normal behavior as all paths are likely returning a value as
all paths are ending with end function (and the implicit return value is
false). IMO you have rather this warning when you use the "exit function"
statement ??


Consider this sample:

\\\
Public Function Foo() As Object
If True Then
Return "x"
End If
End Function
///

This function implicitly returns 'Nothing' on all code paths too if no
return value is set. So I do not think that this is a big difference to the
scenario the OP described, although the warning is shown for the code above.

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

Jan 3 '06 #15
Ken,

"Ken Halter" <Ken_Halter@Use _Sparingly_Hotm ail.com> schrieb:
i have inherited the following migrated vb6 code (vb2005)
but i DONT get the "not all paths return a value" squiggly - is this a
'feature' of on error goto?

Errors:

End Function


I've read a few of these answers that state something along the lines of:
Just put a "CreateFold er = False" line after the "Errors:" label.


That should never be required. Since False is the default return value for
any boolean function/variable/whatever, explicitly setting the return =
False should never be required. If it is suddenly required after 30 years
of programming, there should be a huge notice posted on the web somewhere
that says "forget about your existing source code, everything has suddenly
changed for no good reason"


You could actually disable the warning. Simply open up the project file in
a text editor and add the warning number (42105) to the 'NoWarn' element.
My main concern is that the warning only occurs at functions which return a
reference type.

The full text of the warning makes this more clear: "[...] A null reference
exception could occur at run time when the result is used". I do not think
that implicitly returning 'Nothing' is a big problem. The main problem is
IMO forgetting to set a return value for a certain code path inside the
function. The same problem applies to BC42104 too. I have summed up my
thoughts on the usefulness of this warning in an article (in German):

Zur Sinnhaftigkeit der Compilerwarnung BC42104
<URL:http://dotnet.mvps.org/dotnet/articles/bc42104/>

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

Jan 3 '06 #16
Sorry I don"t have 2005 hand. Even with a boolean return value ? What is the
code create for this ? I wonder what is the exact condition that triggres
this warning...

--
Patrice

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> a écrit dans le
message de news:eP******** ******@TK2MSFTN GP14.phx.gbl...
"Patrice" <no****@nowhere .com> schrieb:
Looks like a normal behavior as all paths are likely returning a value as all paths are ending with end function (and the implicit return value is
false). IMO you have rather this warning when you use the "exit function" statement ??
Consider this sample:

\\\
Public Function Foo() As Object
If True Then
Return "x"
End If
End Function
///

This function implicitly returns 'Nothing' on all code paths too if no
return value is set. So I do not think that this is a big difference to

the scenario the OP described, although the warning is shown for the code above.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 3 '06 #17
"Patrice" <no****@nowhere .com> schrieb:
Sorry I don"t have 2005 hand. Even with a boolean return value ? What is
the
code create for this ? I wonder what is the exact condition that triggres
this warning...


The warning will only work if the function's return type is a reference
type.

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

Jan 3 '06 #18
Thanks for the follow up...

--
Patrice

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> a écrit dans le
message de news:e$******** *****@tk2msftng p13.phx.gbl...
"Patrice" <no****@nowhere .com> schrieb:
Sorry I don"t have 2005 hand. Even with a boolean return value ? What is
the
code create for this ? I wonder what is the exact condition that triggres this warning...


The warning will only work if the function's return type is a reference
type.

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

Jan 3 '06 #19
On Tue, 3 Jan 2006 19:21:52 +0100, "Herfried K. Wagner [MVP]"
<hi************ ***@gmx.at> wrote:
"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNO SPAM> schrieb:
To me it seems that they have forgotten to implement the check for 'On
Error
GoTo'...


As far as I understand it, the squiggly lines are not based on the
source text you see, but what the parser turns it into. Which in this
case is an entirely different beast. See my other post.


The occurance of the warning depends on the return type of the function. So
it's not actually a bug, but I believe the warning could have been
implemented in a way that it is also shown for functions which return a
value type.


Care to give me an example that involves On Error Goto?

It is true that the squiggly lines appear for

Public Function ObjectDoesProdu ceSquiggleLines () As Object
'Do nothing
End Function

but not for

Public Function ValueProducesNo SquiggleLines() As Boolean
Dim b As Boolean = True
End Function

But when the "On Error ..." abomination is used, as in the sample
the original poster provided ...

Check the samples below. None of them produce squiggly lines, even
though I am fairly positive that they cover both objects and value
types as return values. I see no difference in behavior due to
the choice of return types.

If you look at what the compiler turns the samples into, you will
see that something is explicitly returned on all code paths in all
samples.

---snip---
Option Explicit On
Option Strict On
....
Public Function GetString() As String
On Error GoTo someerror
Return ""
SomeError:
End Function

Public Function GetObject() As Object
On Error GoTo SomeError
Return Nothing
SomeError:
End Function

Public Function GetBoolean() As Boolean
On Error GoTo SomeError
Return False
SomeError:
End Function

Public Function GetArrayList() As ArrayList
On Error GoTo SomeError
Return New ArrayList
SomeError:
End Function
---snip---

Regards,

Joergen Bech

Jan 3 '06 #20

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

Similar topics

6
3440
by: Bruce W.1 | last post by:
The intent of my web service is an RSS feed from a blog. Originally I used a StringBuilder to make the XML and returned a string from the webmethod. But this doesn't display properly in IE. So now I'm trying an XmlTextWriter instead. I whipped-up another webservice based on this: http://www.codeproject.com/aspnet/RSSviaXmlTextWriter.asp?print=true This example isn't set up strictly as a webservice. It seems to output to an aspx...
5
6759
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() { throw new Exception("exception thrown"); }
12
4134
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport) {
4
13013
by: OutdoorGuy | last post by:
Greetings, I am attempting to compile the code below, but I am receiving an error message when I do so. The error message is: "CSO161: 'Forloop.CalcAvg(int)': Not all code paths return a value". Any idea as to what I'm doing wrong? I'm sure it's something simple. Thanks in advance! public class ForLoop
3
8645
by: Oberon | last post by:
How do I deal with this? I am getting an error for each get in the Game class (see code below). In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I have added 3 records to the table and ran the program but it fails with the error above. The application is supposed to create the hashtable of records as a static feature which will be permanently available to my application. To demonstrate that...
7
11617
by: Robert | last post by:
I have the function below. it returns a "simpleresult" which I've also included the definition of below. In VS2005 (after upgrading the project), I get a warning indicating that Function 'CloseVantive' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. The code runs fine. But why do I get this message? How do i get rid of it? The only thing I found is if i add a...
1
1381
by: UJ | last post by:
I am doing development on a machine and everything was working fine. The name of the project was ECS to I made all my references as ~/ECS/... Worked great. Put it on the final server running 2003/IIs 6and it bitched it couldn't find the directory. I created a virtual directory, it complained because web.config wasn't there. I removed the ECS from all the references and it works great on both my devo and the final machine.
1
1823
by: fretIT | last post by:
Hello, when I write web method using C# in Visual basic 2005, I can't return the string value to the client request. I got such kind of error Not all code paths return a value. Don't know how to cope that problem. My code is as follow. Thanks in advance
4
10285
Markus
by: Markus | last post by:
I have a method that checks whether the passed argument is present in an array. The method needs to return a bool value. Take a look at said method: private bool IPExist(string IP) { // We need to check if the IP exists in the // IP array foreach (string x in IPs) { if (x == IP)
0
9700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10546
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9121
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5498
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
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 we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.