Oppure

Loading
03/06/07 9:22
Roberto VB
Salve, sto lavorando alla mia chat da un po' di tempo, ora però ho trovato un problema :D

'Se txtInvia contiene almeno un carattere allora invia il messaggio
If txtInvia.SelStart > 0 Then
Data = "Client sta scrivendo un messaggio"
TCP.SendData Data
'Altrimenti non invia nulla
Else
Data = " "
TCP.SendData Data
End If


Con questo codice ogni volta che scrivo un messaggio, l'altro utente riceve in una textbox un messaggio avvisandolo che sto scrivendo.
Il problema sta nel fatto che il codice si trova nell'evento change della textbox e quindi si verifica ogni volta che digito un carattere, di conseguenza se scrivo velocemente Data non è più "Client sta scrivendo un messaggio", ma "Client sta scrivendo un messaggio""Client sta scrivendo un messaggio""Client sta scrivendo un messaggio""Client sta scrivendo un messaggio" . per cui quando si verifica DataArrival non esegue:
If Data = " " Then txtStato.Text = "": Exit Sub
If Data = "Client sta scrivendo un messaggio" Then
txtStato.Text = "Client sta scrivendo un messaggio"
Exit Sub
End If

visto che Data non è più "Client sta scrivendo un messaggio"

Dim Data As String
TCP.GetData Data
If Data = " " Then txtStato.Text = "": Exit Sub
If Data = "Client sta scrivendo un messaggio" Then
txtStato.Text = "Client sta scrivendo un messaggio"
Exit Sub
End If
If Data = "Hai ricevuto un trillo!" Then Beep
lblStato.Caption = "In arrivo " & bytesTotal & "Bytes"
txtChat.Text = txtChat.Text & " Remoto> " & Data & vbCrLf
txtChat.SelStart = Len(txtChat.Text)
txtStato.Text = ""


E' un pochino complicato da spiegare spero che abbiate capito!! ;) In caso contrario ditemelo!!
aaa
03/06/07 12:52
P4p3r0g4
non basterebbe mettere una variabile booleana a true quando la tua textbox non è vuota e a false quando lo è e inviare a ogni cambiamento di testo il valore della variabile?
aaa
03/06/07 14:01
Roberto VB
Però non so su che evento inserire il codice. In change non penso che può funzionare, perchè l'evento si verifica ogni volta che inserisco un carattere
aaa
03/06/07 18:00
SuperTiz
Proviamo con il suggerimento di Paperoga, che mi sembra molto valido




sto per dare una risposta affrettata, cmq prova cosi

scrivi

Dim X as Boolean
If txtInvia.SelStart > 0 then
X = true
else
X = false
end if
If X = true then
Data = "Client sta scrivendo un messaggio"
TCP.SendData Data
Else
Data = " "
TCP.SendData Data
End If


dovrebbe andare, se x è vero allora visualizza il messaggio, se è falso no..
prova e facci sapere!
Ultima modifica effettuata da SuperTiz 03/06/07 18:01
aaa
03/06/07 19:25
Roberto VB
Avevo già provato in questo modo, comunque ho inserito il codice che mi hai suggerito e il problema persiste. Appena comincio a scrivere velocemente compare:

Remoto> Client sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggioClient sta scrivendo un messaggio
aaa
03/06/07 19:25
Roberto VB
Ultima modifica effettuata da Roberto VB 03/06/07 19:29
aaa
03/06/07 19:26
Roberto VB
Ultima modifica effettuata da Roberto VB 03/06/07 19:29
aaa
04/06/07 12:20
P4p3r0g4
Private sub txtinvia_change()
Dim X as Boolean
If txtInvia = "" then
X = false
else
X = true
end if
if x = true
TCP.SendData "true"
else
TCP.SendData "false"
end if
end sub


nel dataarrival

if datiricevuti = true
text1.text = "il clinet sta scrivendo un messaggio"
elseif datiricevuti = false 
text1.text = ""
end if
Ultima modifica effettuata da P4p3r0g4 04/06/07 12:21
aaa