frmChat.frm

 VERSION 5.00
Begin VB.Form frmChat
   Caption         =   "Form1"
   ClientHeight    =   5925
   ClientLeft      =   75
   ClientTop       =   360
   ClientWidth     =   8295
   LinkTopic       =   "Form1"
   ScaleHeight     =   5925
   ScaleWidth      =   8295
   StartUpPosition =   3  'Windows Default
   Begin VB.Timer Timer1
      Interval        =   100
      Left            =   5040
      Top             =   5400
   End
   Begin VB.TextBox txtMessage
      Height          =   375
      Left            =   120
      TabIndex        =   3
      Top             =   4800
      Width           =   5895
   End
   Begin VB.CommandButton cmdSend
      Caption         =   "&Send"
      Height          =   375
      Left            =   6240
      TabIndex        =   2
      Top             =   4800
      Width           =   1335
   End
   Begin VB.ListBox lstUsers
      Height          =   3960
      ItemData        =   "frmChat.frx":0000
      Left            =   6240
      List            =   "frmChat.frx":0002
      Sorted          =   -1  'True
      TabIndex        =   1
      Top             =   720
      Width           =   1935
   End
   Begin VB.ListBox lstMessage
      Height          =   3960
      ItemData        =   "frmChat.frx":0004
      Left            =   120
      List            =   "frmChat.frx":0006
      TabIndex        =   0
      Top             =   720
      Width           =   5895
   End
   Begin VB.Label lblUser
      Caption         =   "ganesh"
      Height          =   255
      Left            =   840
      TabIndex        =   4
      Top             =   240
      Width           =   1815
   End
End
Attribute VB_Name = "frmChat"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim con As Connection
Dim rs As Recordset
Dim rsGetMessage As Recordset
Dim cmd As Command


Private Sub cmdSend_Click()

Dim strInsert As String

If lstUsers.List(lstUsers.ListIndex) = Empty Then

   MsgBox "Choose a User Name First", vbCritical
  
Else

   If txtMessage.Text = Empty Then
  
       MsgBox "Please Type some message", vbCritical
      
       Else

strInsert = "Insert into chat values('" & lblUser.Caption & "','" & txtMessage.Text & "','" & lstUsers.List(lstUsers.ListIndex) & "','" & Date + Time & "')"
cmd.ActiveConnection = con
cmd.CommandText = strInsert
cmd.Execute strInsert


    End If
   
End If

'MsgBox lstUsers.List(lstUsers.ListIndex)





End Sub

Private Sub Form_Load()

Set con = New Connection
Set rs = New Recordset
Set rsGetMessage = New Recordset
Set cmd = New Command

con.Open "Provider=SQLOLEDB.1;Password=;User ID=sa;Initial Catalog=pubs;Data Source="

rs.Open "Select * from regis", con, adOpenDynamic, adLockOptimistic


While rs.EOF = False

lstUsers.AddItem rs.Fields(0)
rs.MoveNext

Wend

lblUser.Caption = strUser

End Sub



Private Sub Timer1_Timer()

rsGetMessage.Open "Select * from chat where tmail ='" & lblUser.Caption & "'", con, adOpenDynamic, adLockOptimistic

If rsGetMessage.BOF And rsGetMessage.EOF Then

Else

lstMessage.Clear

While rsGetMessage.EOF = False

lstMessage.AddItem rsGetMessage.Fields(0) + "          " + rsGetMessage.Fields(1)
rsGetMessage.MoveNext

Wend

End If
rsGetMessage.Close

End Sub

Project Homepage: