473,789 Members | 3,060 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 #1
25 2572

It is recommended that classic VB6 error handling be replaced
with structured exception handling.

But to answer your specific question: In the code, no specific value
is returned in the (empty) error handler.

Just put a "CreateFold er = False" line after the "Errors:" label.

Note: You can also write "Return <value>" instead of
"<function name> = <value>".

/Joergen Bech

On Tue, 3 Jan 2006 08:30:06 -0800, guy <gu*@discussion s.microsoft.com >
wrote:
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 #2
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 #3
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.


I'm sure he realises that, the question was as to why he *didn't* get a
compiler warning. I would have expected there to be one too.

--

(O)enone
Jan 3 '06 #4
guy
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 #5
"guy" <gu*@discussion s.microsoft.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?

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


To me it seems that they have forgotten to implement the check for 'On Error
GoTo'...

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

Jan 3 '06 #6

Whoops. Misread the original post. .Net Reflector to the rescue.

This is what the code is turned into:

---snip---
Private Shared Function CreateFolder(By Val sFileName As String) As
Boolean
Dim flag1 As Boolean
Dim num2 As Integer
Try
ProjectData.Cle arProjectError
Dim num1 As Integer = 2
If Not Directory.Exist s(sFileName) Then
Directory.Creat eDirectory(sFil eName)
End If
flag1 = True
goto Label_0066
Label_0025:
num2 = -1
Select Case num1
Case 0, 1
goto Label_005B
Case 2
goto Label_0066
End Select
Catch obj1 As Object When (?)
ProjectData.Set ProjectError(CT ype(obj1, Exception))
goto Label_0025
End Try
Label_005B:
Throw ProjectData.Cre ateProjectError (-2146828237)
Label_0066:
If (num2 <> 0) Then
ProjectData.Cle arProjectError
End If
Return flag1
End Function
---snip---

Dim flag1 As Boolean means that flag1 is implicitly initialized
to False by .Net.

So all code paths are indeed satisfied.

But it sure is ugly.

Regards,

Joergen Bech

On Tue, 3 Jan 2006 09:02:03 -0800, guy <gu*@discussion s.microsoft.com >
wrote:
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 #7

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******** *************** ***********@mic rosoft.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 #8
On Tue, 3 Jan 2006 18:31:58 +0100, "Herfried K. Wagner [MVP]"
<hi************ ***@gmx.at> wrote:
"guy" <gu*@discussion s.microsoft.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?

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


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.

I see no bugs.

/JB

Jan 3 '06 #9

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 #10

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
4133
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
13012
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
11616
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
1380
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
9665
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
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
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
9020
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...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
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.