First of all thanking everyone....
I am currently working on VB. I am using Visual Studio 2008.
The piece of code below is a console application which builds without any error.
Imports System.Net
Module Module1
Public Sub Main()
Dim address As IPAddress
Dim remoteIP As System.Net.IPEndPoint
Dim socketAddress As System.Net.SocketAddress
Try
address = IPAddress.Parse("192.168.0.187")
remoteIP = New System.Net.IPEndPoint(address, 0)
socketAddress = remoteIP.Serialize()
Console.WriteLine("Address Family :" & remoteIP.AddressFamily.ToString())
Console.WriteLine("IP :" & remoteIP.Address.ToString() & "Port :" & remoteIP.Port.ToString())
Console.WriteLine("Socket address :" & socketAddress.ToString())
Catch ex As Exception
Console.WriteLine(ex.StackTrace.ToString())
End Try
End Sub
End Module
In the next program which is a dll the same gives error saying "Declaration Expected for addr, remoteIP and socketAddr"
Imports System.Net
Public Class Class1
End Class
Public Class ethernet
Dim addr As IPAddress
Dim remoteIP As System.Net.IPEndPoint开发者_Go百科
Dim socketAddr As System.Net.SocketAddress
addr = IPAddress.Parse("192.168.0.187")
remoteIP = New System.Net.IPEndPoint(addr,0)
socketAddr = remoteIP.Serialize()
End Class
Can anybody tell me why is this happening...
Your code in the second class ethernet
is not contained within a Method, therefore you are only declaring the addr, remoteIP
and socketAddr
variables.
To make that work just put the code in a method, like:
Public Class ethernet
Public Function SerializeSocket(address As String) As System.Net.SocketAddress
Dim addr As IPAddress = IPAddress.Parse("192.168.0.187")
Dim remoteIP As System.Net.IPEndPoint = New System.Net.IPEndPoint(addr,0)
Return remoteIP.Serialize()
End Sub
End Class
精彩评论