Support Forums

Full Version: VB - Chat program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Here is a simple chat program that uses IP's to talk to each other.
You can adapt it to work how you like;

[Image: 9ti9gx.jpg]


Code:
Imports VB = Microsoft.VisualBasic
Public Class frmChat
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer
    Dim UserID As String

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        End
    End Sub

    Private Sub btnMySend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMySend.Click
        Dim Message As String
        Message = "[" & UserID & "] " & txtMySend.Text

        AxWinsock1.RemoteHost = AxWinsock1.LocalIP
        AxWinsock1.SendData(Of Date)()
        If AxWinsock1.LocalIP = txtIPAddress.Text Then
            AxWinsock1.RemoteHost = txtIPAddress.Text
            AxWinsock1.SendData(Message)
        End If
        txtMySend.Text = ""
        txtMySend.Focus()
    End Sub

    Private Sub frmChat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AxWinsock1.Protocol = MSWinsockLib.ProtocolConstants.sckTCPProtocol
        AxWinsock1.RemoteHost = AxWinsock1.LocalIP
        AxWinsock1.RemotePort = 10
        AxWinsock1.LocalPort = 11

        Dim sBuffer As String
        Dim lSize As Integer
        sBuffer = Space(255)
        lSize = Len(sBuffer)
        Call GetUserName(sBuffer, lSize)
        If lSize > 0 Then
            UserID = VB.Left(sBuffer, lSize - 1)
        Else
            UserID = vbNullString
        End If
        Me.Text = Me.Text + UserID & " at " & AxWinsock1.LocalIP
        txtIPAddress.Text = AxWinsock1.LocalIP
        txtMyIP.Text = AxWinsock1.LocalIP
    End Sub

    Private Sub AxWinsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles AxWinsock1.DataArrival
        Dim Arrival As String = ""
        AxWinsock1.GetData(Arrival)
        txtMyArrival.Text = txtMyArrival.Text & Arrival & vbNewLine
    End Sub
    Private Sub txtIPAddress_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtIPAddress.Leave
        AxWinsock1.RemoteHost = txtIPAddress.Text
    End Sub
End Class
Nice Program Good Work!
Smart and Crafty... I like it! Thanks for the application!
Can't believe it!

I did not know there was a simple program such as this that does these kind of things!

LOVE IT!
(11-09-2010, 01:34 PM)Currymanz Wrote: [ -> ]Can't believe it!

I did not know there was a simple program such as this that does these kind of things!

LOVE IT!

If there's anything else you require just ask. I'll do the best I can. (:
So basically you connect to someone's ip that has this program, and you can talk to each other?
(11-11-2010, 05:54 PM)Jet Wrote: [ -> ]So basically you connect to someone's ip that has this program, and you can talk to each other?

That's correct.
GUI is a little basic, but that's nothing that can't be easily sorted. VERY nice work amigo.
Yeah it is. It was only to show how it works. I wasn't actually using it for anything.
(11-13-2010, 01:57 PM)Ameise Wrote: [ -> ]Yeah it is. It was only to show how it works. I wasn't actually using it for anything.

Well I really like it, and it is something I will use Thumbsup. I will have to wait until I get comp out of safe mode though as it won't let me download VB Sad .
Pages: 1 2 3