Jelajahi eBook
Kategori
Jelajahi Buku audio
Kategori
Jelajahi Majalah
Kategori
Jelajahi Dokumen
Kategori
Pada contoh kali ini saya akan membuat program yang memanfaatkan salah satu fungsi
string pada pemrograman Visual Basic 6.0 yaitu membuat waktu, baiklah langkah
pertama susun dulu tool-tool yang dibutuhkan, susun seperti gambar dibawah ini:
Pada contoh kali ini saya akan menjelaskan cara membaca dan menulis ke
file di dalam Visual Basic. Perogram ini hampir sama dengan notepad, tapi
tanpa ANSII, Dan data dapat kita simpan secara permanent ke dalam disk,
langsung pada pembahasannya. Langkah pertama buka program Visual
Basic 6.0, Lalu setelah terbuka tekan tombol Ctrl+T pada keyboard maka
akan keluar Component, Lalu cari dan centang Microsoft Common Dialog
Control 6.0 lalu OK, Setelah itu desaign tampilan form sebagai berikut ini:
Membuat teks berjalan di form
Pada tutorial kali ini hanya tambahan iseng-iseng dari saya, namun lumayan lah
manfaatnya, yaitu membuat teks di form berjalan sepeti animasi,, Dengan memansaatkan
event timer yang ada di Visual Basic 6.0, Langsung saja pada pembahasannya, pertama
buka Visual Basic 6.0 nya dan pilih Standart Exe, Lalu Isi toolnya seperti ini:
Lalu buka listing program dan CoPas listingnya menjadi seperti ini:
The Transfer Control Protocol (TCP) is used to create and maintain a connection to a
remote computer. To set the Winsock control to TCP, set Winsock's Protocol Property to
"sckTCPProtocol". The computers are able to share information through the
connection. The Client must know the Server's name or Internet Protocol IP address,
set in the RemoteHost Property of the Winsock control. The Client must also know the
Port number on which the Server will be listening, set in the RemotePort Property of the
Winsock control.
If tcpClient.RemoteHost = "" Then
tcpClient.RemoteHost = "localhost"
End If
tcpClient.RemotePort = 3456
tcpClient.Connect
The LocalPort Property must be set on the Server to specify which Port it is listening to.
tcpServer.LocalPort = 3456
tcpServer.Listen
When the Client requests a connection, the ConnectionRequest Event occurs. The
Accept method is used within the ConnectionRequest event to complete the connection.
When connected, information is sent and received using the SendData and GetData
methods. When data is received, the DataArrival Event occurs.
The following describes how to create a simple TCP based chat program. The program
consists of two parts, a server and a client.
The Server Application has a Winsock control named tcpServer using the Protocol
sckTCPProtocol, and two TextBoxes, named txtOutput and txtSend. txtOutput's
MultiLine Property is set to True.
Option Explicit
Private Sub Form_Load()
txtSend.Enabled = False
txtOutput.Enabled = False
tcpServer.LocalPort = 3456
tcpServer.Listen
End Sub
Private Sub Form_Unload(Cancel As Integer)
tcpServer.Close
End Sub
Private Sub tcpServer_Close()
txtSend.Enabled = False
txtOutput.Enabled = False
tcpServer.Close
txtOutput.Text = txtOutput.Text & "Client closed connection"
& vbCrLf & vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
tcpServer.Listen
End Sub
Private Sub tcpServer_ConnectionRequest(ByVal requestID As
Long)
If tcpServer.State <> sckClosed Then
tcpServer.Close
End If
txtSend.Enabled = True
txtOutput.Enabled = True
tcpServer.Accept requestID
txtOutput.Text = tcpServer.RemoteHostIP & ":" & _
tcpServer.RemotePort & _
" connected" & vbCrLf & vbCrLf
End Sub
Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
Dim msg As String
tcpServer.GetData msg
txtOutput.Text = txtOutput.Text & msg & vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
End Sub
Private Sub tcpServer_Error(ByVal Number As Integer,
Description As String, _
ByVal Scode As Long, ByVal Source As String, ByVal
HelpFile As String, _
ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox Source & ": " & Description, vbExclamation,
"TCP/IP Error"
End Sub
Private Sub txtOutput_GotFocus()
If txtOutput.Enabled = True Then
txtSend.SetFocus
End If
End Sub
Private Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
tcpServer.SendData "SERVER: " & txtSend.Text
txtOutput.Text = txtOutput.Text & "SERVER: " &
txtSend.Text & vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
txtSend.Text = ""
End If
End Sub
The Client Application has a Winsock control named tcpClient using the Protocol
sckTCPProtocol, and two TextBoxes named txtOutput and txtSend. txtOutput's
MultiLine Property is set to True.
Option Explicit
Private Sub Form_Load()
Dim strPrompt As String
TCO/IP APPLICATION:
The User Datagram Protocol (UDP) is a Connectionless protocol and unlike TCP does
not establish a connection. To set the Winsock control to UDP, set Winsock's Protocol
Property to sckUDPProtocol. The computers are able to share information through the
connection. Data is sent by setting the Client's LocalPort property and the Server's
RemoteHost and RemptePort Properties to the Internet address and LocalPort Property of
the Client.
Data is sent and received using the SendData and GetData methods. When data is
received, the DataArrival Event occurs.
The Server Application has a Winsock control named udpServer using the Protocol
sckUDPProtocol, and two TextBoxes named txtOutput and txtSend. txtOutput's
MultiLine Property is set to True.
Option Explicit
Private Sub Form_Load()
udpServer.Bind 3456
End Sub
Private Sub Form_Unload(Cancel As Integer)
udpServer.Close
End Sub
Private Sub udpServer_DataArrival(ByVal bytesTotal As Long)
Dim msg As String
udpServer.GetData msg
txtOutput.Text = txtOutput.Text & udpServer.RemoteHostIP
txtOutput.Text = txtOutput.Text & ":" &
udpServer.RemotePort
txtOutput.Text = txtOutput.Text & " " & msg & vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
End Sub
Private Sub txtOutput_GotFocus()
txtSend.SetFocus
End Sub
Private Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
udpServer.SendData txtSend.Text
txtOutput.Text = txtOutput & "Sent: " & txtSend.Text &
vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
txtSend.Text = ""
End If
End Sub
The Client Application has a Winsock control named udpClient using the Protocol
sckUDPProtocol, and two TextBoxes named txtOutput and txtSend. txtOutput's
MultiLine Property is set to True.
Option Explicit
Private Sub Form_Load()
Dim msg As String
msg = "Enter the IP address of the server"
udpClient.RemoteHost = InputBox(msg, "IP Address",
"localhost")
If udpClient.RemoteHost = "" Then
udpClient.RemoteHost = "localhost"
End If
udpClient.RemotePort = 3456
End Sub
Private Sub Form_Unload(Cancel As Integer)
udpClient.Close
End Sub
Private Sub udpClient_DataArrival(ByVal bytesTotal As Long)
Dim msg As String
udpClient.GetData msg
txtOutput.Text = txtOutput.Text & udpClient.RemoteHostIP
txtOutput.Text = txtOutput.Text & ":" &
udpClient.RemotePort
txtOutput.Text = txtOutput.Text & " " & msg & vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
End Sub
Private Sub txtOutput_GotFocus()
txtSend.SetFocus
End Sub
Private Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
udpClient.SendData txtSend.Text
txtOutput.Text = txtOutput.Text & "Sent: " &
txtSend.Text & vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
txtSend.Text = ""
End If
End Sub
If you don't find what you are looking for. Please click here to submit your query,