-
[RESOLVED] Winsock: sending content of combobox from server to client
Hey everyone. I'm new to this forum and I need some help with Winsock. Well theres a combobox on my client and a combobox on the server. Lets say the combobox on the server was filled. How can i send the same exact content of the server combobox to the combobox on my client ?? Thx in advance :)
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
Hey everyone. I'm new to this forum and I need some help with Winsock. Well theres a combobox on my client and a combobox on the server. Lets say the combobox on the server was filled. How can i send the same exact content of the server combobox to the combobox on my client ?? Thx in advance :)
You could do this:
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
VB Code:
Private Sub sckClient_DataArrival(ByVal bytesTotal As Long)
Dim str As String, tmp() As String, i As Integer
'put the data recieved into str$
sckClient.GetData str$, vbString
'seperate each with Split()
tmp$() = Split(str$, "||||")
'tmp$(0) is the ListCount
For i% = 1 to CInt(tmp$(0))
cboClient.AddItem tmp$(i%)
Next i%
End Sub
-
Re: Winsock: sending content of combobox from server to client
What if the content isnt always the same. It changes according to some input. Btw, what if im not friends with arrays ? :p
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
What if the content isnt always the same. It changes according to some input. Btw, what if im not friends with arrays ? :p
If your not good with arrays i'm sure there is tutorials around, but there is other ways like:
VB Code:
Private Sub Command1_Click()
Dim i As Integer
'send each item one by one, this will take longer if you have a very long list,
'and you should probably use arrays.
For i% = 0 to cboServer.ListCount - 1
sckServer.SendData cboServer.List(i%)
Next i%
End Sub
VB Code:
Private Sub sckClient_DataArrival(ByVal bytesTotal As Long)
Dim str As String
'get the data sent by server
sckClient.GetData str$, vbString
'add the item to the client combo
cboClient.AddItem str$
End Sub
I don't get what you mean what if the content changes? can you explain more?
-
Re: Winsock: sending content of combobox from server to client
Well I probably need to read some more tuts, though i read about arrays and understood them. I just think that they're hard to use when things get complicated, which is why i never bothered reading again. Any advice ? Btw, what does the % stand for ?
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
Well I probably need to read some more tuts, though i read about arrays and understood them. I just think that they're hard to use when things get complicated, which is why i never bothered reading again. Any advice ? Btw, what does the % stand for ?
They just help you read code easier and so you can tell what that variable is. Like:
String: $
Long: &
Integer: %
You don't need them, but I suggest you use them if you have a very long function or just for anything.
-
Re: Winsock: sending content of combobox from server to client
Hey i got to understand arrays now :) but what i was saying is that maybe my combo1.Listcount kept on changing........let me think of an example. Lets say im inserting the online contacts of my msn, they're not always constant you know so the listcount will change. I cant use like Number(1 to Combo1.listcount) can I ? Btw, i got it all except the ending, when u split them (confusing) and CInt...
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
Hey i got to understand arrays now :) but what i was saying is that maybe my combo1.Listcount kept on changing........let me think of an example. Lets say im inserting the online contacts of my msn, they're not always constant you know so the listcount will change. I cant use like Number(1 to Combo1.listcount) can I ? Btw, i got it all except the ending, when u split them (confusing) and CInt...
Yes you can use this method, but you can only update the list when the user isn't looking at it (there is probably another method than this, but you can try this):
VB Code:
Private Sub cboClient_DropDown()
'stop the timer from updating until we lose focus
Timer1.Enabled = False 'timer1 is how we are updating are list, you don't have to use a timer, but you can
End Sub
Private Sub cboClient_LostFocus()
'start the timer again
Timer1.Enabled = True
End Sub
CInt(expression) is used to convert an expression (in this case a string) into an integer.
Split(expression,delimiter,limit,compare) is used to split a string into pieces everytime it hits the delimiter. If you want more information on this look-it-up in MSDN, or type it in your code-window then right-click on it and find "definition" and click it.
So if you had:
VB Code:
Dim str As String, tmp() As String
str$ = "Welcome to VBForums"
We want to get each word by itself, and as you can see each word is seperated with a space.
VB Code:
tmp$() = Split(str$," ") 'we don't need to use limit, or compare these are optional
'we would then end up with tmp$(0 to 2)
'tmp$(0) would be "Welcome"
'tmp$(1) would be "to"
'tmp$(2) would be "VBForums"
-
Re: Winsock: sending content of combobox from server to client
Got error "Subscript out of range" at the level of: For i = 1 to CInt(tmp(0))
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
Got error "Subscript out of range" at the level of: For i = 1 to CInt(tmp(0))
ops, I forgot to fix that try:
VB Code:
For i% = 1 to CInt(tmp$(0)) - 1
-
Re: Winsock: sending content of combobox from server to client
Hey it worked ! Thx a lot man :) But i seem to have a problem...what if i want to receive more data on the client? like the .Getdata function will get messed up. You see it only worked when i removed all the other Data im receiving... what's the solution ? How can i separate one data from the other ?
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
Hey it worked ! Thx a lot man :) But i seem to have a problem...what if i want to receive more data on the client? like the .Getdata function will get messed up. You see it only worked when i removed all the other Data im receiving... what's the solution ? How can i separate one data from the other ?
Yes I usually do this by sending a command with it , for example:
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$ = Right$(dataRecieved$, Len(dataRecieved$) - 6)
realData$ = Left$(dataRecieved, Len(dataRecieved$) - Len(dataRecieved$) + 6)
Select Case dataCommand$
Case "LISTU="
'seperate each with Split()
tmp$() = Split(str$, "||||")
'tmp$(0) is the ListCount
For i% = 1 to CInt(tmp$(0)) - 1
cboClient.AddItem tmp$(i%)
Next i%
End Select
End Function
You can add more commands, but they must be six characters long like "LISTU=", after the six characters is the data you want. You can then add a another case and do whatever you want with the data.
-
Re: Winsock: sending content of combobox from server to client
Umm i think i would understand if u ADD to that last post a Case where you send a message from the server and receive it through msgbox in client for instance....very much appreciated.
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
Umm i think i would understand if u ADD to that last post a Case where you send a message from the server and receive it through msgbox in client for instance....very much appreciated.
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$ = Right$(dataRecieved$, Len(dataRecieved$) - 6)
realData$ = Left$(dataRecieved, Len(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
Sorry, and I made an error in the splitting I fixed that, forgot to change the variable, and to call this msgbox you can do this:
VB Code:
sckClient.SendData "MSGBX=Hello, Welcome to my project!"
-
Re: Winsock: sending content of combobox from server to client
Ummm if i want it like to send whats in a text box? like txtbox = txtmsg.Text
Winsock.Senddata txtbox
Btw, you didnt include LISTU= in the data being sent.
-
Re: Winsock: sending content of combobox from server to client
Quote:
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
-
Re: Winsock: sending content of combobox from server to client
Im sorry, you posted before i edited the post.
Ummm if i want it like to send whats in a text box? like txtbox = txtmsg.Text
Winsock.Senddata txtbox
Btw, you didnt include LISTU= in the data being sent.
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
Im sorry, you posted before i edited the post.
Ummm if i want it like to send whats in a text box? like txtbox = txtmsg.Text
Winsock.Senddata txtbox
Btw, you didnt include LISTU= in the data being sent.
VB Code:
Dim Msg As String
Msg$ = txtmsg.Text
Winsock1.SendData Msg$
Yes just like that, and what do you mean I didn't add "LISTU=" in the data being sent?
-
Re: Winsock: sending content of combobox from server to client
Well wouldnt it be like Winsock.Senddata LISTU=arr$ or something ?
And about that Senddata Msg$ how do i interpret it ? Whats the datacommand and all ? this is what confuses me.... like when sending strings or sending a real msg " "
-
Re: Winsock: sending content of combobox from server to client
Quote:
Originally Posted by Karimz
Well wouldnt it be like Winsock.Senddata LISTU=arr$ or something ?
And about that Senddata Msg$ how do i interpret it ? Whats the datacommand and all ? this is what confuses me.... like when sending strings or sending a real msg " "
To send the command "LISTU=" you first need to get all the items from the ComboBox, you can do this like this:
VB Code:
Function SetupLISTU(ByRef combo As Object) As String
Static i As Integer, arr As String
For i% = 0 to combo.ListCount - 1
If Len(arr$) = 0 Then
arr$ = combo.ListCount & "||||" & combo.List(i%)
Else
arr$ = arr$ & "||||" & combo.List(i%)
End If
Next i%
SetupLISTU$ = "LISTU=" & arr$
End Function
Private Sub cmdUpdateList_Click() 'update the list
sckServer.SendData SetupLISTU$(cboServer)
End Sub
'to send a message
Private Sub cmdMessage_Click() 'send message
sckServer.SendData "MSGBX=Hello"
End Sub
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
Hey heres what im trying to do now: i have 3 combo boxes on the server, and im trying to send each combobox's data to be received by one treeview on the client, where the content of combobox1 has 1 image, that of combobox2 has its own image, and that of combobox3 has its own image in that treeview on the client. Heres what i have done, but the problem is that the treeview is facing problems....data is successfully being sent to client but the data is wrongly being interpreted.
VB Code:
Private Sub Command1_Click()
Dim arr(0 To 2) As String, i As Integer, j As Integer, onlinearr As String, awayarr As String, busyarr As String
For j% = 0 To 2
For i% = 0 To Combo1(j).ListCount - 1
If Len(arr(j)) = 0 Then
arr(j) = Combo1(j).ListCount & "||||" & Combo1(j).List(i%)
Else
arr(j) = arr(j) & "||||" & Combo1(j).List(i%)
End If
Next i%
Next j%
onlinearr$ = "Onlin=" & arr$(0)
awayarr$ = "Away1=" & arr$(1)
busyarr$ = "Busy1=" & arr$(2)
If Combo1(0).ListCount > 0 Then sckserver.SendData onlinearr$
If Combo1(1).ListCount > 0 Then sckserver.SendData awayarr$
If Combo1(2).ListCount > 0 Then sckserver.SendData busyarr$
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData Data
EvaluateData Data
Function EvaluateData(ByVal dataRecieved As String) As Long
Dim tmp() As String, i As Integer, bu() As String, k As Integer, aw() As String, j As Integer
Dim dataCommand As String, realData As String
dataCommand$ = Left$(dataRecieved, 6)
realData$ = Right$(dataRecieved$, Len(dataRecieved$) - 6)
Select Case dataCommand$
Case "Onlin="
tmp$() = Split(realData$, "||||")
For i% = 1 To CInt(tmp$(0))
Formcontact.TreeView1.Nodes.Add , , , tmp$(i%), "Online"
Next i%
Case "Away1="
aw$() = Split(realData$, "||||")
For j% = 1 To CInt(aw$(0))
Formcontact.TreeView1.Nodes.Add , , , aw$(j%), "Away"
Next j%
Case "Busy1="
bu$() = Split(realData$, "||||")
For k = 1 To CInt(bu$(0))
Formcontact.TreeView1.Nodes.Add , , , bu$(k%), "Busy"
Next k
End Select
End Function
What i get is the content of combobox1(0).... but near the last item in the list i see Away1=4 :confused:
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
@XRsTX - why are you bothering with the DropDown handle? I think that the Validate handle should do the job. It triggers every time Combo receives a new item:
VB Code:
Private Sub Combo1_Validate(Cancel As Boolean)
'your code
End Sub
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
Hey gavio, if u continued reading the thread, i decided to use a treeview instead of a combobox. Besides, i think a clear button should do a good job, i just clear the list and update it again using a Get List button for example. Btw, did you check the last post for me, im having trouble now again :rolleyes: I appreciate any help provided.
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
What is causing the problem? Case "Away1="?
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
Well only case "Onlin=" is working, the other cases arent working. I even tried deleting Case "Online=" (but didnt delete the other 2 cases) but the treeview remained empty then. Before deleting Case "Online=", lets say the last item on the list was "Joe", i saw instead "JoeAway1=4" or something like that, it even appears sometimes on another item not necessarily the last one. "Busy1=" isnt working either.
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
Well... put this between those two lines (to see exactly the data you are receiving):
VB Code:
Winsock1.GetData Data
[B]MsgBox Data[/B]
EvaluateData Data
Data is a string, right?
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
Yea its a string. Well all the data i see in the msgbox is correct, but it looks like its all in one block, the 3 contents are attached to each other, its like its all one case...maybe its because im sending the 3 data at the same time ?
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
That's the reason (proboball) why your code didn't work. You'll have to split those 3in1 contents to 3 separate strings. Something is wrong in the code where you send your data... Just a hint: everytime something doesn't work, and you can't figure it out, put MsgBox between each line and you'll probobally find out the problem.
edit: I don't think so. Each instruction executes individually.
-
Re: [RESOLVED] Winsock: sending content of combobox from server to client
Well thx, i'll try my best :) Was thinking of using timers...i'll see if i can figure it out on my own, thx a lot again.
Edit: So should i work at the end where the data is being sent or the end where its being received ?