|
-
Jan 22nd, 2003, 02:18 PM
#1
Thread Starter
Member
Sendin And REcieving List Box info via Winsock...
could somebody give me guideance on sending the data contained in 3 listboxes from the server, to client, via winsock...
I have 3 listboxes on the server App:
List1.............List2............List3
string...........string...........(string or integer, yet to decide)
And exactly the same, but empty on the client side...How can i get this data accross, keeping the data in the correct listboxes, and correct row...
Thank you for any assistance/links
Dave
-
Jan 22nd, 2003, 11:57 PM
#2
I did not test the code, but theoreticly it's something like this
VB Code:
' to send the data
Private Sub Form_Load()
Dim PB As New PropertyBag, K As Long
Dim DataToSend() As Byte
List1.AddItem "df"
List1.AddItem "sdff"
List1.AddItem "rtwf"
List1.AddItem "ytret"
List1.AddItem "ertu"
List1.AddItem "gfhjg"
List1.AddItem "bvnmbn"
List2.AddItem "qwerqwe"
List2.AddItem "123413"
List2.AddItem "fgfsdf"
List2.AddItem "vbnvtyrt"
List2.AddItem "drtigeri"
List3.AddItem "uiuoi"
List3.AddItem "sdfgdsf"
List3.AddItem "zxcv"
List3.AddItem "zxcv"
List3.AddItem "qwr"
List3.AddItem "tryuty"
List3.AddItem "cvbcvbvbv"
PB.WriteProperty "LST1_COUNT", List1.ListCount
For K = 0 To List1.ListCount - 1
PB.WriteProperty "LST1_" & K, List1.List(K)
Next K
PB.WriteProperty "LST2_COUNT", List2.ListCount
For K = 0 To List2.ListCount - 1
PB.WriteProperty "LST2_" & K, List2.List(K)
Next K
PB.WriteProperty "LST3_COUNT", List3.ListCount
For K = 0 To List3.ListCount - 1
PB.WriteProperty "LST3_" & K, List3.List(K)
Next K
DataToSend() = PB.Contents
Winsock1.SendData "DATA_LENGTH={" & (UBound(DataToSend) + 1) & "}="
Winsock1.SendData PB.Contents
End Sub
' when receiving data
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Static TotalLength As Long, MyData As String
Dim mData As String, DataReceived() As Byte, PB As New PropertyBag, K As Long
Winsock1.GetData mData
If mData Like "DATA_LENGTH={#*}=" And TotalLength = 0 Then
TotalLength = Val(Mid(mData, InStr(1, mData, "={") + 3))
mData = Mid(mData, InStr(1, mData, "}=") + 3)
End If
MyData = MyData & mData
If Len(MyData) >= TotalLength Then
DataReceived() = StrConv(MyData, vbUnicode)
PB.Contents = DataReceived
For K = 0 To Val(PB.ReadProperty("LST1_COUNT"))
List1.AddItem PB.ReadProperty("LST1_" & K)
Next K
For K = 0 To Val(PB.ReadProperty("LST2_COUNT"))
List2.AddItem PB.ReadProperty("LST2_" & K)
Next K
For K = 0 To Val(PB.ReadProperty("LST3_COUNT"))
List3.AddItem PB.ReadProperty("LST3_" & K)
Next K
TotalLength = 0
MyData = ""
End If
End Sub
-
Jan 23rd, 2003, 12:10 AM
#3
I just tested the code I pasted previously, and I had some small mistakes, otherwise it works perfectly...
VB Code:
' when receiving data
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Static TotalLength As Long, MyData As String
Dim mData As String, DataReceived() As Byte, PB As New PropertyBag, K As Long
Winsock1.GetData mData
If mData Like "DATA_LENGTH={#*}=*" And TotalLength = 0 Then
TotalLength = Val(Mid(mData, InStr(1, mData, "={") + 2))
mData = Mid(mData, InStr(1, mData, "}=") + 2)
End If
MyData = MyData & mData
If Len(MyData) >= TotalLength Then
DataReceived() = StrConv(MyData, vbFromUnicode)
PB.Contents = DataReceived
For K = 0 To Val(PB.ReadProperty("LST1_COUNT")) - 1
List1.AddItem PB.ReadProperty("LST1_" & K)
Next K
For K = 0 To Val(PB.ReadProperty("LST2_COUNT")) - 1
List2.AddItem PB.ReadProperty("LST2_" & K)
Next K
For K = 0 To Val(PB.ReadProperty("LST3_COUNT")) - 1
List3.AddItem PB.ReadProperty("LST3_" & K)
Next K
TotalLength = 0
MyData = ""
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|