Solved

Splitting received data from winsock client into text boxes

Posted on 2004-04-04
8
355 Views
Last Modified: 2013-11-13
Hello, I am trying to split received data from a winsock client into 4 text feilds. I have tried this method but I am getting the error "Runtime Error '9" "Subscript out of range". I cannot see why though, please help.

Here is my code.

'Sending Data
Dim str As String
str = Text1.Text & Chr$(0) & Text2.Text & Chr$(0) & Text4.Text & Chr$(0)
Winsock1.SendData str

'Receiving Data
Dim sArrParams() As String
Winsock1.GetData Data

sArrParams = Split(Data, Chr$(0))
Text1.Text = sArrParams(0)
Text2.Text = sArrParams(1)
Text3.Text = sArrParams(2)
Text4.Text = sArrParams(3)
0
Comment
Question by:Razorknight
  • 4
  • 3
8 Comments
 
LVL 6

Expert Comment

by:mirzas
ID: 10752997
define sArrParams as

Dim sArrParams(0 to 3) as String


if that does not work make sure you got all of the things you sent.
0
 
LVL 5

Expert Comment

by:drnick
ID: 10756103
str = Text1.Text & Chr$(0) & Text2.Text & Chr$(0) & Text4.Text & Chr$(0)

there are only three strings
text3.text is missing
0
 

Author Comment

by:Razorknight
ID: 10756852
Hmm, thanks guys, I tried adding text3 and also setting sArrParams(0 to 3) but...

but I get this error when sending: "compile error" "cant assign to array"

here is new code...

Dim sArrParams(0 To 3) As String
Winsock1.GetData Data

sArrParams = Split(Data, Chr$(0))
Text1.Text = sArrParams(0)
Text2.Text = sArrParams(1)
Text3.Text = sArrParams(2)
Text4.Text = sArrParams(3)

Please assist me further.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:Razorknight
ID: 10756859
ack, I forget to show where error occured...

Dim sArrParams(0 To 3) As String
Winsock1.GetData Data

sArrParams = Split(Data, Chr$(0)) 'Error here
Text1.Text = sArrParams(0)
Text2.Text = sArrParams(1)
Text3.Text = sArrParams(2)
Text4.Text = sArrParams(3)
0
 
LVL 6

Expert Comment

by:mirzas
ID: 10763896
How did you define Data?
0
 
LVL 6

Accepted Solution

by:
mirzas earned 100 total points
ID: 10763912
ah.. sorry define sArrParams  like this


Dim sArrParams As Variant

that will fix "cant assign to array"


0
 
LVL 6

Expert Comment

by:mirzas
ID: 10763954
here this code worked for me


Private Sub Command1_Click()
    Dim tmp As String
   
    tmp = Text1.Text & Chr$(0) & Text2.Text & Chr$(0) & Text3.Text & Chr$(0) & Text4.Text & Chr$(0)
   
   
    wsk1.Close
    wsk2.Close
    wsk2.LocalPort = 1234
    wsk2.Listen
    wsk1.Connect "localhost", 1234
   
   
    Do
        DoEvents
    Loop Until wsk1.State = sckConnected
   
   
    wsk1.SendData tmp
End Sub

Private Sub Form_Unload(Cancel As Integer)
    wsk2.Close
    wsk1.Close
End Sub

Private Sub wsk2_ConnectionRequest(ByVal requestID As Long)
    wsk2.Close
   
    wsk2.Accept requestID
End Sub

Private Sub wsk2_DataArrival(ByVal bytesTotal As Long)
    Dim tmp As String
   
   
    wsk2.GetData tmp
    'If Len(tmp) <> bytesTotal Then MsgBox "whoops"
   
    Dim foo As Variant
   
   
    foo = Split(tmp, Chr$(0))
   
    MsgBox foo(0)
    MsgBox foo(1)
    MsgBox foo(2)
    MsgBox foo(3)
   
End Sub

0
 

Author Comment

by:Razorknight
ID: 10806032
Yep, that worked, cheers!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now