[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Splitting received data from winsock client into text boxes

Posted on 2004-04-04
8
Medium Priority
?
385 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Progress
Suggested Courses

656 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