
Originally Posted by
Karimz
how does it know that the LISTU= case is the one for the combobox thingy while the MSGBX= is for the msgbox ?
VB Code:
dataCommand$ = Left$(dataRecieved, Len(dataRecieved$) - Len(dataRecieved$) + 6)
realData$ = Right$(dataRecieved$, Len(dataRecieved$) - 6)
This is the part where we seperate the data we want, from the command that seperates each case. Like if our data was:
"MSGBX=Hello"
dataCommand$ deletes the actual data and leaves just the Command.
realData$ deletes the command, btu leaves the data we want to display.
Now that this is done we can put them into cases and give them each stuff to do. This is how it knows what to do, you can add more cases if you want.
Sorry, and I made another mistake, this should work:
VB Code:
Private Sub Command1_Click()
'put each item into an arr$, the delimiter (seperator) is ||||, on the client
Dim arr As String, i As Integer
'put all the data into an array string, we will seperate this once recieved at client
For i% = 0 To cboServer.ListCount - 1
If Len(arr$) = 0 Then
arr$ = cboServer.ListCount & "||||" & cboServer.List(i%)
Else
arr$ = arr$ & "||||" & cboServer.List(i%)
End If
Next i%
sckServer.SendData arr$ 'send the data to the client
End Sub
Private Sub sckClient_DataArrival(ByVal bytesTotal As Long)
Dim str As String
'put the data recieved into str$
sckClient.GetData str$, vbString
'evaluate the data recieved from the client
EvaluateData& str$
End Sub
Function EvaluateData(ByVal dataRecieved As String) As Long
Dim tmp() As String, i As Integer
'the actual data is after the first 6 characters, for example:
'LISTU=the rest of the data recieved, LISTU stands for LIST UPDATE
'dataCommand is the command sent by the client, like LISTU,
'realData is the data after the dataCommand, the actual data we want.
Dim dataCommand As String, realData As String
dataCommand$ = Left$(dataRecieved, Len(dataRecieved$) - Len(dataRecieved$) + 6)
realData$ = Right$(dataRecieved$, Len(dataRecieved$) - 6)
Select Case dataCommand$
Case "LISTU="
'seperate each with Split()
tmp$() = Split(realData$, "||||")
'tmp$(0) is the ListCount
For i% = 1 to CInt(tmp$(0)) - 1
cboClient.AddItem tmp$(i%)
Next i%
Case "MSGBX="
MsgBox realData$, vbOkOnly + vbSystemModal, "My Project"
End Select
End Function