- 爱易网页
-
C#教程
- 哪位高手能把C#2003程序转成VB2005
日期:2014-05-19 浏览次数:20764 次
谁能把C#2003程序转成VB2005?
谁能把C#2003程序转成VB2005?我用转换工具转换后问题很多。谁能帮忙转换下啊,给分或者人民币都可以,有兴趣的可以联系我QQ 20309785
------解决方案--------------------
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.SelectionLength = 0
Dim address As String = "192.168.1.1 "
Dim port As Int32 = Int32.Parse( "23 ")
Dim IPHost As IPHostEntry = Dns.GetHostEntry(address)
Dim aliases() As String = IPHost.Aliases
Dim addr() As IPAddress = IPHost.AddressList
Try
' Create New Socket
Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' Create New EndPoint
Dim iep As New IPEndPoint(addr(0), port)
' This is a non blocking IO
s.Blocking = False
' Assign Callback function to read from Asyncronous Socket
Dim callbackProc As New AsyncCallback(ConnectCallback)
' Begin Asyncronous Connection
s.BeginConnect(iep, callbackProc, s)
Catch eeeee As Exception
MessageBox.Show(eeeee.Message, "Application Error!!! ", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Application.Exit()
End Try
End Sub
Public Sub ConnectCallback(ByVal ar As IAsyncResult)
Try
' Get The connection socket from the callback
Dim sock1 As Socket = CType(ar.AsyncState, Socket)
If sock1.Connected Then
' Define a new Callback to read the data
Dim recieveData As New AsyncCallback(OnRecievedData)
' Begin reading data asyncronously
sock1.BeginReceive(m_byBuff, 0, m_byBuff.Length, SocketFlags.None, recieveData, sock1)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Setup Recieve callbackProc failed! ")
End Try
End Sub
Public Sub OnRecievedData(ByVal ar As IAsyncResult)
' Get The connection socket from the callback
Dim sock As Socket = CType(ar.AsyncState, Socket)
' Get The data , if any
Dim nBytesRec As Int32 = sock.EndReceive(ar)
If (nBytesRec > 0) Then
Dim sRecieved As String = Encoding.ASCII.GetString(m_byBuff, 0, nBytesRec)
Dim m_strLine As String = " "
For i As Int32 = 0 To nBytesRec - 1
Dim ch As Char = Convert.ToChar(m_byBuff(i))
Select Case ch
Case "\r "
m_strLine += Convert.ToString( "\r\n ")
Case "\n "
Case Else
m_strLine += Convert.ToString(ch)
End Select
Next
'try
Dim strLinelen As Int32 = m_strLine.Length
If strLinelen = 0 Then
m_strLine = Convert.ToString( "\r\n ")
End If
Dim mToProcess(strLinelen) As Byte
For i As Int32 = 0 To strLinelen - 1
mToProcess(i) = Convert.ToByte(m_strLine(i))
Next