Solved

Splitting received data from winsock client into text boxes

Posted on 2004-04-04
8
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

688 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