Results 1 to 4 of 4

Thread: [RESOLVED] No value on all code paths

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Resolved [RESOLVED] No value on all code paths

    Hi Guys,

    In more and more of my functions (althought they still work) i'm getting a warning the function doesn't return a value on all code paths.

    for example:

    vb.net Code:
    1. Function functionLoadHiddenFields(ByVal fileLocation As String, ByVal Y As Integer)
    2.  
    3.         '// Check if the file exists
    4.         If File.Exists(fileLocation) Then
    5.  
    6.             '// Load the xml document
    7.             Dim XMLDoc As New Xml.XmlDocument
    8.  
    9.             '// Find and load the XML file
    10.             XMLDoc.Load(fileLocation)
    11.  
    12.             '// Tell where to look for the data we need
    13.             Dim XMLItem As Xml.XmlNode = XMLDoc.SelectSingleNode("hiddenFields/hiddenValues")
    14.  
    15.             'MessageBox.Show((XMLItem.Attributes("hiddenFieldsID" & (Y)).InnerText))
    16.             Return XMLItem.Attributes("hiddenFieldsID" & (Y)).InnerText
    17.  
    18.         End If
    19.  
    20.     End Function

    if i put in the return false it wouldn't show the message, is it basically a way of saying:

    if expression true do this, return true, else return false

    i know in PHPO for example i can just return either true, or a value.

    thanks for any info guys

    Graham

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: No value on all code paths

    If the "IF" evaluates false then the sub does not return anything.

    You're also missing the type of what you're returning;

    Function functionLoadHiddenFields(ByVal fileLocation As String, ByVal Y As Integer) As String

    So you might want to do something like;

    If Whatever
    Return TheValue
    Else
    Return String.Empty
    End If

    Although I'd be inclined to return the state of whether the file was found and pass the acquired value back as a parameter.
    Last edited by Bulldog; Aug 26th, 2009 at 01:37 PM.

  3. #3
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: No value on all code paths

    I'm not sure what PHPO is, but in VB you cannot return True, OR a value. You can return a Boolean (which is True or False), or any other type (Integer, String, your custom class, etc), but you cannot really mix them up.

    The error is because the function does not return anything when the If statement is false. You could simply add an Else statement, and return something appropriate there. For example, you could return an empty string. If that's appropriate in your situation depends on what your situation is. If the Innertext could return an empty string, and if that would be perfectly valid, then that gets dangerous, because you cannot distinguish between an empty string due to the If statement being false, and an empty string that is valid.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Re: No value on all code paths

    Hi Guys,

    Sorry that was a type, it was meant to be PHP lol

    That was probably a bad example to show i am still deciding what if anything i'm doing with that function lol, i understand what i'm doing now

    thanks for the input guys

    Graham

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width