Tôi bây giờ muốn viết một chương trình bằng VisualBasic để từ một máy có thể điều khiển được các máy khác hoặc từ một máy có nhận thông tin từ các máy khác một cách trực tuyến, nhưng tôi không biết có cách nào để làm được điều đấy. Nếu các bạn biết xin hãy chỉ giùm tôi. Tôi xin cảm ơn.
LuatPT
Hồi âm:
Ban men! Toi viet ra chuong trinh Visual Basic dieu khien may tinh nay cho ban de nghien cuu them.
Public Function vbConnect(ByVal lngSocket As Long, _
ByVal strRemoteHost As String, _
ByVal intRemotePort As Integer) As Long Dim udtSocketAddress As sockaddr_in
Dim lngReturnValue As Long
Dim lngAddress As Long
vbConnect = SOCKET_ERROR
If Not lngSocket > 0 Then
Exit Function
End If
If Len(strRemoteHost) = 0 Then
Exit Function
End If
If Not intRemotePort > 0 Then
Exit Function
End If
Dim objProtocol As New CProtocol
Dim lngAdrFamily As Long
lngAdrFamily = objProtocol.AddressFamily
lngAddress = GetAddressLong(strRemoteHost)
If lngAddress = INADDR_NONE Then
Exit Function
End If
.sin_addr = lngAddress
.sin_port = htons(UnsignedToInteger(CLng(intRemotePort)))
.sin_family = lngAdrFamily
End With
vbConnect = connect(lngSocket, udtSocketAddress, LenB(udtSocketAddress))
Exit Function
If Not objProtocol Is Nothing Then
Set objProtocol = Nothing
End If
vbConnect = SOCKET_ERROR
End Function
Dim lngRetValue As Long lngRetValue = vbConnect If lngRetValue = 0 Then
MsgBox "Connected!"
Else
Call ShowErrorMessage(Err.LastDllError)
End If
Private Sub cmdConnect_Click()
Dim frm As frmConnect
Dim lngSocket As Long
Dim strRemoteHost As String
Dim intRemotePort As Integer
Dim lngRetValue As Long
Set frm = New frmConnect
.Show vbModal
If .Result Then
strRemoteHost = .RemoteHost
intRemotePort = .RemotePort
Else
Set frm = Nothing
Exit Sub
End If
End With
Set frm = Nothing
lngSocket = CLng(lvSockets.SelectedItem.Text)
lngRetValue = modWinsockAPI.vbConnect(lngSocket, strRemoteHost, intRemotePort)
If lngRetValue = SOCKET_ERROR Then
Else
lvSockets.SelectedItem.Bold = True
lvSockets.SelectedItem.SmallIcon = 2
End If
End Sub
Chuc ban vui ve!
Phucusa
VB không thích hợp cho những công việc phức tạp, đòi hỏi kiến thức chuyên sâu như thế này. Theo tôi, VB dành cho những người học lập trình để giải trí. Cho dù bạn có thể dùng các controls do người khác viết, nhưng bạn phải biết nhiều kiến thức khác thì mới xài được. Đối với người đang học để trở thành professional thì việc nắm vững kiến thức cơ bản là điều tối quan trọng. Trên Windows, bạn nên học lập trình bằng C/C++.
Đào Thanh Ngọc