|
-
Aug 26th, 2007, 11:36 PM
#1
Thread Starter
Hyperactive Member
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
-
Aug 27th, 2007, 12:01 AM
#2
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.
-
Aug 27th, 2007, 02:53 AM
#3
Thread Starter
Hyperactive Member
Re: Converting Project from vb.net 2003 to vb.net 2005
vb Code:
Private Function RetDay(ByVal dt As Integer) As String
Select Case dt
Case 1
RetDay = "Monday"
Case 2
RetDay = "TuesDay"
Case 3
RetDay = "Wednesday"
Case 4
RetDay = "Thursday"
Case 5
RetDay = "Friday"
Case 6
RetDay = "Saturday"
Case 0
RetDay = "Sunday"
End Select
Return RetDay
End Function
'Variable 'RetDay' is used before it has been assigned a value. A null reference exception could result at runtime.
Public Function GetSingleData(ByVal StrQuery As String)
Try
OpenConnection()
SqlCom.CommandType = CommandType.Text
SqlCom.CommandText = StrQuery
GetSingleData = SqlCom.ExecuteScalar
CloseConnection()
Return GetSingleData
Catch ex As Exception
MsgBox(ex.ToString)
CloseConnection()
Return Nothing
End Try
End Function
'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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|