Solved

Splitting received data from winsock client into text boxes

Posted on 2004-04-04
8
339 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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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.
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…

747 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

8 Experts available now in Live!

Get 1:1 Help Now