Results 1 to 3 of 3

Thread: Converting Project from vb.net 2003 to vb.net 2005

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Converting Project from vb.net 2003 to vb.net 2005

    Hi,

    I have an application in vb.net 2003 and now converted to vb.net 2005
    Application is running properly but some warning message is show in error list..
    Code:
     Public Function UserIpAddress()
            Try
                Dim IntPos As Integer
                Dim strDecode As String
                Dim hostName As String = System.Net.Dns.GetHostName
                Dim IpAddress As String = System.Net.Dns.GetHostEntry(hostName).AddressList(0).ToString
                For IntPos = 1 To Len(IpAddress)
                    strDecode = strDecode & SmEncrypt(Mid(IpAddress, IntPos, 1))
                Next
                UserIpAddress = strdecode
                Return UserIpAddress
            Catch ex As Exception
                Exit Function
            End Try
        End Function
    
    ‘—Function 2
    Private Function RetDay(ByVal dt As Integer) As String
    	Select Case dt
    	Case 1
    	           RetDay = "Monday"
    	Case 0
    		RetDay = "Sunday"
            End Select
        End Function
    Following warning has been given: Function 1

    1. Function without an 'AS' clause ; return type of object assumed.

    2. Function 'UserIpAddress' doesn't return a value on all code paths.
    A null reference exception could occur at run time when the result is used.

    Function 2:
    Warinig: Function 'RetDay' doesn't return a value on all code paths.
    A null reference exception could occur at run time when the result is used.
    --If I write the return retday in every case than also the same warning is given


    Me.Cursor.Current = Cursors.WaitCursor
    (warinig: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.)

    If I write the code trn.rollback in catch
    variable 'trn' is used before it has been assigned a value.
    A null reference exception could result at runtime.


    thanks

    asm

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Converting Project from vb.net 2003 to vb.net 2005

    1. You haven't specified what type the UserIpAddress method returns. If it returns a String then declare it as so:
    Code:
    Public Function UserIpAddress() As String
    2. If an exception is thrown your UserIpAddress method doesn't return a value. You should NEVER use Exit Function. If you don't want a value returned then you should specify exactly that with Return Nothing.

    3. Your RetDay function doesn't return a value. While it's legal you should not simply rely on the implicit local variable to supply the return value. Every function should have a Return statement and it should not be possible for the method to complete without reaching a Return statement. Again, it's legal but it's bad practice. The warning message is because the compiler doesn't know whether you've done it on purpose or not so it's warning you that the function may not return a value.

    4. By using the name Cursor you are referring to the form's Cursor property. To refer to the Cursor class you must qualify the name:
    Code:
    Me.Cursor.Current = Windows.Forms.Cursors.WaitCursor
    5. To clear that warning assign Nothing to the variable where you declare it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Re: Converting Project from vb.net 2003 to vb.net 2005

    vb Code:
    1. Private Function RetDay(ByVal dt As Integer) As String
    2.         Select Case dt
    3.             Case 1
    4.                 RetDay = "Monday"
    5.             Case 2
    6.                 RetDay = "TuesDay"
    7.             Case 3
    8.                 RetDay = "Wednesday"
    9.             Case 4
    10.                 RetDay = "Thursday"
    11.             Case 5
    12.                 RetDay = "Friday"
    13.             Case 6
    14.                 RetDay = "Saturday"
    15.             Case 0
    16.                 RetDay = "Sunday"
    17.         End Select
    18.         Return RetDay
    19.     End Function
    20. 'Variable 'RetDay' is used before it has been assigned a value. A null reference exception could result at runtime.
    21.  
    22. Public Function GetSingleData(ByVal StrQuery As String)
    23.         Try
    24.             OpenConnection()
    25.             SqlCom.CommandType = CommandType.Text
    26.             SqlCom.CommandText = StrQuery
    27.             GetSingleData = SqlCom.ExecuteScalar
    28.             CloseConnection()
    29.             Return GetSingleData
    30.         Catch ex As Exception
    31.             MsgBox(ex.ToString)
    32.             CloseConnection()
    33.             Return Nothing
    34.         End Try
    35. End Function
    36. 'Function without an 'As' clause; return type of Object assumed.

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