Aberf
June 22nd, 2001, 01:01 AM
I'm making a chat program with a server app and a client app, but for some reason, the server app i skipping an if, even when it shouldn't.
Server:
private Sub Wsk_DataArrival(Index as Integer, byval bytesTotal as Long)
on error resume next
'variables
Dim Msg as string
Dim SplitMsg() as string
Dim a as Integer
'receive the message
Wsk(Index).GetData Msg, vbString
'splite the message to make sure no messages will overlap
SplitMsg = Split(Msg, Chr$(0))
'check to see what kind of message it is
If Left$(Msg, 1) = Chr$(2) then
'if text then send the message to all the users
for a = 1 to maxusers
Wsk(a).SendData mid$(Msg, 2) & vbCrLf & Chr$(0)
DoEvents
next a
txtOutput.Text = txtOutput.Text & mid$(Msg, 2) & vbCrLf
End If
If Left$(Msg, 1) = Chr$(10) then
'receive the new user's user name and update the user list
lstUsers.List(Index - 1) = mid$(Msg, 2)
'tell the other users that the new user has signed in
for a = 1 to maxusers
Wsk(a).SendData lstUsers.List(Index - 1) & " has signed in." & vbCrLf & Chr$(0)
DoEvents
next a
'write that the new user has signed in
txtOutput.Text = txtOutput.Text & lstUsers.List(Index - 1) & " has signed in." & vbCrLf
End If
Label5.Caption = "55"
'skips the if below for the password send
If Left$(Msg, 1) = Chr$(7) then
Label5.Caption = "1"
Open App.Path + "\Users\" + lstUsers.List(Index - 1) + ".xfd" for input as #1
input #1, UName$
input #1, Pass$
Label2.Caption = UName$
Label3.Caption = Pass$
Label4.Caption = lstUsers.List(Index - 1)
Close #1
Label5.Caption = "2"
If Not Pass$ = mid$(Msg, 2) then
Label5.Caption = "3"
for a = 1 to maxusers
If lstUsers.List(Index - 1) = UName$ then
Wsk(a).Close
Label5.Caption = "4"
DoEvents
Label5.Caption = "5"
End If
Label5.Caption = "6"
next a
End If
Label5.Caption = "9"
End If
Close #1
End Sub
Client:
private Sub Wsk_Connect()
'tell when the user connected to the server
txtOutput.Text = txtOutput.Text & "Connected to the server at " & time & vbCrLf
'send the server the user's username
Wsk.SendData Chr$(10) & frmStart.UName & Chr$(0)
Wsk.SendData Chr$(7) & frmStart.Pass & Chr$(0)
DoEvents
End Sub
It is probably something very simple, but I can;t figure it out. The user name and text parts both work, but the password part doesn't. :(. And label 5 is 55 at the end, meaning it didn;t think that the if was equal.
Server:
private Sub Wsk_DataArrival(Index as Integer, byval bytesTotal as Long)
on error resume next
'variables
Dim Msg as string
Dim SplitMsg() as string
Dim a as Integer
'receive the message
Wsk(Index).GetData Msg, vbString
'splite the message to make sure no messages will overlap
SplitMsg = Split(Msg, Chr$(0))
'check to see what kind of message it is
If Left$(Msg, 1) = Chr$(2) then
'if text then send the message to all the users
for a = 1 to maxusers
Wsk(a).SendData mid$(Msg, 2) & vbCrLf & Chr$(0)
DoEvents
next a
txtOutput.Text = txtOutput.Text & mid$(Msg, 2) & vbCrLf
End If
If Left$(Msg, 1) = Chr$(10) then
'receive the new user's user name and update the user list
lstUsers.List(Index - 1) = mid$(Msg, 2)
'tell the other users that the new user has signed in
for a = 1 to maxusers
Wsk(a).SendData lstUsers.List(Index - 1) & " has signed in." & vbCrLf & Chr$(0)
DoEvents
next a
'write that the new user has signed in
txtOutput.Text = txtOutput.Text & lstUsers.List(Index - 1) & " has signed in." & vbCrLf
End If
Label5.Caption = "55"
'skips the if below for the password send
If Left$(Msg, 1) = Chr$(7) then
Label5.Caption = "1"
Open App.Path + "\Users\" + lstUsers.List(Index - 1) + ".xfd" for input as #1
input #1, UName$
input #1, Pass$
Label2.Caption = UName$
Label3.Caption = Pass$
Label4.Caption = lstUsers.List(Index - 1)
Close #1
Label5.Caption = "2"
If Not Pass$ = mid$(Msg, 2) then
Label5.Caption = "3"
for a = 1 to maxusers
If lstUsers.List(Index - 1) = UName$ then
Wsk(a).Close
Label5.Caption = "4"
DoEvents
Label5.Caption = "5"
End If
Label5.Caption = "6"
next a
End If
Label5.Caption = "9"
End If
Close #1
End Sub
Client:
private Sub Wsk_Connect()
'tell when the user connected to the server
txtOutput.Text = txtOutput.Text & "Connected to the server at " & time & vbCrLf
'send the server the user's username
Wsk.SendData Chr$(10) & frmStart.UName & Chr$(0)
Wsk.SendData Chr$(7) & frmStart.Pass & Chr$(0)
DoEvents
End Sub
It is probably something very simple, but I can;t figure it out. The user name and text parts both work, but the password part doesn't. :(. And label 5 is 55 at the end, meaning it didn;t think that the if was equal.