7 Replies - 1449 Views - Last Post: 13 May 2009 - 12:26 AM Rate Topic: -----

#1 jasperno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 08-January 09

Splitting incoming data

Post icon  Posted 11 May 2009 - 12:47 AM

hi, i'm making project which sends data between 2 forms on LAN, this data controls different buttons etc on the server form.. the problem i have is that sometimes the code on the recieving end mixes up like this,vscroll123Vscroll234, what i am wondering if it is possible to set a rule that all incoming data gets Split up with a delemetor or something xD, this is my recieve.data code

Private Sub sockmain_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strData As String




sockmain(Index).GetData strData, vbString
txtstatus.Text = txtstatus.Text & _
	  strData & vbCrLf

If InStr(strData, "connect") Then Call Connect_Click
If InStr(strData, "0,1,") Then Check3(0).Value = 1
If InStr(strData, "0,0,") Then Check3(0).Value = 0
If InStr(strData, "1,1,") Then Check3(1).Value = 1
If InStr(strData, "1,0,") Then Check3(1).Value = 0
If InStr(strData, "2,1,") Then Check3(2).Value = 1
If InStr(strData, "2,0,") Then Check3(2).Value = 0
If InStr(strData, "3,1,") Then Check3(3).Value = 1
If InStr(strData, "3,0,") Then Check3(3).Value = 0
If InStr(strData, "4,1,") Then Check3(4).Value = 1
If InStr(strData, "4,0,") Then Check3(4).Value = 0
If InStr(strData, "5,1,") Then Check3(5).Value = 1
If InStr(strData, "5,0,") Then Check3(5).Value = 0
If InStr(strData, "6,1,") Then Check3(6).Value = 1
If InStr(strData, "6,0,") Then Check3(6).Value = 0
If InStr(strData, "7,1,") Then Check3(7).Value = 1
If InStr(strData, "7,0,") Then Check3(7).Value = 0
If Left$(strData, 8) = "vscroll1" Then VScroll1.Value = Mid(strData, 9)
If Left$(strData, 8) = "vscroll2" Then VScroll2.Value = Mid(strData, 9)
If Left$(strData, 15) = "clearallanalog1" Then Call ClearAllAnalog1_Click
If Left$(strData, 13) = "setallanalog1" Then Call SetAllAnalog1_Click
If Left(strData, 9) = "check5aan" Then Timer2.Enabled = True Else Timer2.Enabled = False
If Left$(strData, 11) = "clearalldig" Then Call ClearAllDig_Click
If Left$(strData, 9) = "setalldig" Then Call SetAllDig_Click
If Left$(strData, 11) = "option10aan" Then Option1(0).Value = True
If Left$(strData, 11) = "option11aan" Then Option1(1).Value = True
If Left$(strData, 11) = "option12aan" Then Option1(2).Value = True
If Left$(strData, 11) = "option13aan" Then Option1(3).Value = True
If Left$(strData, 11) = "option20aan" Then Option2(0).Value = True
If Left$(strData, 11) = "option21aan" Then Option2(1).Value = True
If Left$(strData, 11) = "option22aan" Then Option2(2).Value = True
If Left$(strData, 11) = "option23aan" Then Option2(3).Value = True
If Left$(strData, 6) = "reset1" Then Call Reset1_Click
If Left$(strData, 6) = "reset2" Then Call Reset2_Click
If Left$(strData, 3) = "192" Then Label6.Caption = Left(strData, 13)
If Left$(strData, 3) = "192" Then Label8.Caption = Right(strData, 2)
If InStr(strData, "Sockmain2") Then sockmain2.Connect Label6.Caption, Val(Label8.Caption)
End Sub


i just need an example of it so i can change my code:)
thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Splitting incoming data

#2 jasperno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 08-January 09

Re: Splitting incoming data

Posted 11 May 2009 - 10:36 AM

bump,,, i know the split command i just don't know how to use it propperly.. anyone in here who knows and can explain it to me..
Was This Post Helpful? 0
  • +
  • -

#3 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Splitting incoming data

Posted 11 May 2009 - 06:28 PM

try this link

VB String Array Functions - Split, Join, Filter

hope this help you

This post has been edited by thava: 11 May 2009 - 06:28 PM

Was This Post Helpful? 0
  • +
  • -

#4 jasperno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 08-January 09

Re: Splitting incoming data

Posted 12 May 2009 - 02:33 AM

View Postthava, on 11 May, 2009 - 05:28 PM, said:

try this link

VB String Array Functions - Split, Join, Filter

hope this help you


i read that before, but i just don't get it how to insert that into my excisting code, it always fails.. all i'm trying is that every incoming data gets recieved on a new line by using the delimiter, btw i'm new to vb 6.0 this is my first project ever.. xD
thanks for the help so far
Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Splitting incoming data

Posted 12 May 2009 - 02:38 AM

write down your datasending procedure we will help you

This post has been edited by thava: 12 May 2009 - 02:39 AM

Was This Post Helpful? 0
  • +
  • -

#6 jasperno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 08-January 09

Re: Splitting incoming data

Posted 12 May 2009 - 04:48 AM

ok, it's alot tho because the 2 forms look alike they're just server and client.

Private Sub Check3_Click(Index As Integer)
Dim datatosend As String 'tijdenlijke tekst string

  datatosend = Str$(Index) 'alvast nummer er in zetten

  If Check3(Index).Value = 1 Then
	  datatosend = datatosend & ",1,"
  Else
	  datatosend = datatosend & ",0,"
  End If
  sockmain.SendData datatosend   'en nu string versturen
End Sub

Private Sub Check5_Click()
Dim datatosend As String 'tijdenlijke tekst string

  datatosend = "check5" 'alvast nummer er in zetten

  If Check5.Value = 1 Then
	  datatosend = datatosend & "aan"
  Else
	  datatosend = datatosend & "uit"
  End If
  sockmain.SendData datatosend   'en nu string versturen
If Check5.Value = 1 Then Timer2.Enabled = True Else Timer2.Enabled = False
End Sub

Private Sub ClearAllAnalog1_Click()
sockmain.SendData "clearallanalog1"
   ClearAllAnalog
	VScroll1.Value = 0
	VScroll2.Value = 0
	Label3.Caption = 0
	Label4.Caption = 0
End Sub

Private Sub Command1_Click()
	'connects to IP address 127.0.0.1
	'through port 55
	sockmain.Close
 sockmain.Connect Text10.Text, Val(Text11.Text)
 sockmain2.Close
 sockmain2.LocalPort = Text3.Text
 sockmain2.Listen
End Sub


Private Sub Command2_Click()
Label2.Caption = sockmain.LocalIP
End Sub

Private Sub Command3_Click()
sockmain.SendData "Sockmain2"
End Sub

Private Sub Connect_Click()
sockmain.SendData "connect"
End Sub

Private Sub Form_Initialize()
	DoNothing = False
	n = 7
End Sub

Private Sub Form_Load()
	'displays status of winsock
	lblconnect.Caption = "Not Connected"
End Sub

Private Sub Form_Terminate()
	CloseDevice
End Sub



Private Sub Option1_Click(Index As Integer)
Dim datatosend As String 'tijdenlijke tekst string

  datatosend = "option" 'alvast nummer er in zetten

  If Option1(0).Value = True Then
	  datatosend = datatosend & "10aan"
  End If
	If Option1(1).Value = True Then
	  datatosend = datatosend & "11aan"
  End If
	If Option1(2).Value = True Then
	  datatosend = datatosend & "12aan"
  End If
	If Option1(3).Value = True Then
	  datatosend = datatosend & "13aan"
  End If
  sockmain.SendData datatosend   'en nu string versturen
End Sub

Private Sub Option2_Click(Index As Integer)
Dim datatosend As String 'tijdenlijke tekst string

  datatosend = "option" 'alvast nummer er in zetten

  If Option2(0).Value = True Then
	  datatosend = datatosend & "20aan"
  End If
	If Option2(1).Value = True Then
	  datatosend = datatosend & "21aan"
  End If
	If Option2(2).Value = True Then
	  datatosend = datatosend & "22aan"
  End If
	If Option2(3).Value = True Then
	  datatosend = datatosend & "23aan"
  End If
  sockmain.SendData datatosend   'en nu string versturen
End Sub

Private Sub Reset1_Click()
sockmain.SendData "reset1"
End Sub

Private Sub Reset2_Click()
sockmain.SendData "reset2"
End Sub

Private Sub SetAllAnalog1_Click()
sockmain.SendData "setallanalog1"
SetAllAnalog
	VScroll1.Value = 255
	VScroll2.Value = 255
	Label3.Caption = 255
	Label4.Caption = 255
End Sub

Private Sub SetAllDig_Click()
sockmain.SendData "setalldig"
Dim i As Long
	DoNothing = True
	For i = 0 To 7
		Check3(i).Value = 1
	Next
	DoNothing = False
	SetAllDigital
End Sub

Private Sub ClearAllDig_Click()
sockmain.SendData "clearalldig"
 Dim i As Long
	DoNothing = True
	For i = 0 To 7
		Check3(i).Value = 0
	Next
	DoNothing = False
	ClearAllDigital
End Sub


Private Sub sockmain_Close()
lblconnect.Caption = "Disconnected"
End Sub

Private Sub sockmain_Connect()
lblconnect.Caption = "Succesfully connected"
 sockmain2.Close
 sockmain2.LocalPort = Text3.Text
 sockmain2.Listen
sockmain.SendData Label2.Caption & Text3.Text
End Sub

Private Sub sockmain2_Connect()
MsgBox " server connected"
End Sub

Private Sub sockmain2_ConnectionRequest(ByVal requestID As Long)
 sockmain2.Close
 sockmain2.Accept requestID
End Sub


Private Sub VScroll1_change()
Dim datatosend As String 'tijdenlijke tekst string

  datatosend = "vscroll1" 'alvast nummer er in zetten

  If VScroll1.Value >= 1 Then
	  datatosend = datatosend & VScroll1.Value
  End If
  sockmain.SendData datatosend   'en nu string versturen
  Label3.Caption = VScroll1.Value
End Sub

Private Sub VScroll2_change()
Dim datatosend As String 'tijdenlijke tekst string

  datatosend = "vscroll2" 'alvast nummer er in zetten

  If VScroll2.Value >= 1 Then
	  datatosend = datatosend & VScroll2.Value
  Else
	  datatosend = datatosend & VScroll2.Value
  End If
  sockmain.SendData datatosend   'en nu string versturen
	Label4.Caption = VScroll2.Value
End Sub



Was This Post Helpful? 0
  • +
  • -

#7 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Splitting incoming data

Posted 12 May 2009 - 04:38 PM

write down a common procedure for sockmain.senddata

like this or use this procedure instead of sockmain.senddata


public sub SenddatatoClient(byval DataStr as String)

DataStr= DataStr+ vbctrlf ' Add your delimited Charecter here

sockmain.senddata DataStr

End Sub


Private Sub Check3_Click(Index As Integer)
Dim datatosend As String 'tijdenlijke tekst string

  datatosend = Str$(Index) 'alvast nummer er in zetten

  If Check3(Index).Value = 1 Then
      datatosend = datatosend & ",1,"
  Else
      datatosend = datatosend & ",0,"
  End If
  SenddatatoClient  datatosend   'en nu string versturen
End Sub




and one more thing when you make string seperate this with a delimiter
  If Check3(Index).Value = 1 Then
      datatosend = datatosend& ",1,"  & vbctrlf 
  Else
      datatosend = datatosend & ",0,"   & vbctrlf
  End If


This post has been edited by thava: 12 May 2009 - 04:49 PM

Was This Post Helpful? 0
  • +
  • -

#8 jasperno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 08-January 09

Re: Splitting incoming data

Posted 13 May 2009 - 12:26 AM

already got a solution, but i have one problem.. when i send the vscrollvalues it goes like this..

If Left$(strData, 8) = "vscroll1" Then VScroll1.Value = Mid(strData, 9)

this used to work but now that i use the delimiter ":"
Mid(strdata, 9) = XXX: instead of XXX (X represents a number)
so is there a way where i can get the value without the delimiter screwing it up ? :)
thanks for the help so far. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1