Ok, Heres the story. I have all this string data stored in text1. How do I go about sending it over to the server in 200 character intervals using winsock?
Printable View
Ok, Heres the story. I have all this string data stored in text1. How do I go about sending it over to the server in 200 character intervals using winsock?
VB Code:
Private Sub Command1_Click() Dim sbuff As String Dim i As Integer For i = 1 To Len(Text1.Text) Step 200 sbuff = Mid(Text1.Text, i, 200) Winsock1.SendData sbuff DoEvents 'sleep 100 Next i End Sub
Thanks man!
Ok, Now I have another problem. Im using an identifier to tell it where to put the data and the identifier is "txtlog". My problem is that I cannot get "txtlog" to NOT show in frmTxtLog.Text1, so I see a bunch of random "txtlog" all over the place. How do I format it so that it does not show "txtlog"?
Thanks man!
Server -
VB Code:
Public Sub TxtLog() frmMain.Text4 = frmTxtLog.Text1 Dim sbuff As String Dim i As Integer For i = 1 To Len(frmMain.Text4.Text) Step 200 sbuff = Mid(frmMain.Text4.Text, i, 200) frmMain.Winsock1.SendData "txtlog" & sbuff DoEvents Next i end sub
Client -
VB Code:
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long) Winsock1(Index).GetData data If Left$(data, 6) = "txtlog" Then TxtLog1 End Sub Public Sub TxtLog1() If frmTxtLog.Text1 = "" Then frmTxtLog.Text1 = Mid(data, 7, Len(data)) Else frmTxtLog.Text1 = frmTxtLog.Text1 & vbNewLine & Mid(data, 7, Len(data)) End If End Sub
please help me
not with you.
Whats wrong with me?
i mean i dont get your problem.
You have to put the data back together on the receiver end. Something like thisCode:Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Static allData As String
Dim x As String
Dim Lines
Dim i As Integer
Winsock1.GetData x
'put back together
allData = allData & x
'Now you can look for your markers
ipos = InStr(allData, "txtlog")
If ipos > 0 Then
'strip off line
Lines = Split(allData, "txtlog")
For i = 0 To UBound(Lines) - 2
'do what you want with the line here
Call txtLog(Lines(i))
Next i
'save last one
allData = Lines(i)
End If
End Sub
This will save all the data minus "txtlog" in the textbox?Quote:
Originally Posted by moeur
Each call to txtLog gets passed a line of data with the txtlog.
That isnt working for me :(
How do I say put everything but the first 6 characters in the data into txtlog?
That isn't working for me :)Quote:
That isnt working for me
Please provide more information, either explain what is and is not happening, or upload a demo project(s) that we can work with.
Im trying to get the data and display it in the txtlog.text...but with every section i send...it puts the "txtlog" in front of the data I want to see. I dont want to see "txtlog" at the beginning of every chunk that it sends. Im thinking I can just tell it to put all the data..but the 6 first characters in the textbox.
Ok, heres the thing...
winsock1.getdata data
If the first 6 letters of data = txtlog then TxtLog
Public Sub TxtLog
frmmain.txtlog.text = data
end sub
pretty much theres it in short w/o the correct stuff. My problem is that I run the program and grab the data and it shows like this
txtlogajkls dhfasjflka sjflksjflskajlfsatxtlog alkjdflasjflkjdjlfsa djkftxtlogalksdjfl askjftxtlogalksdjfalksjf txtloglas sldfkakdsjfsaklj aksldfjalsfjsakfjsakfj as fatxtlog lkajsdfasjf lasf txtlogalksdjfalsjfd
Notice how there are random "txtlog"'s all over the place because that is in the data that the server sends. So I need to do something like.
winsock1.getdata data
If the first 6 letters of data = txtlog then TxtLog
Public Sub TxtLog
frmmain.txtlog.text = data - the first 6 characters at the beginning
end sub
Is this better explained?
OK, try this to see what I'm trying to do
Note: I've set the Multiline property of Text1 to TrueCode:Option Explicit
Private Sub Command1_Click()
Dim inData As String
Dim splitData() As String
Dim i As Integer
Text1 = ""
inData = "txtlogajkls dhfasjflka sjflksjflskajlfsatxtlog alkjdflasjflkjdjlfsa djkftxtlogalksdjfl askjftxtlogalksdjfalksjf txtloglas sldfkakdsjfsaklj aksldfjalsfjsakfjsakfj as fatxtlog lkajsdfasjf lasf txtlogalksdjfalsjfd"
splitData = Split(inData, "txtlog")
For i = 0 To UBound(splitData) - 1
If Len(Trim(splitData(i))) > 0 Then _
Text1 = Text1 & Trim(splitData(i) & vbCrLf)
Next i
End Sub
Will this work if the data is varying? Cuz obviously more is going to be added to the log.
this only depends on the fact that the strings are separated by your special marker, so if that doesn't vary then it will be fine.
Try it out and see is the best way to answer most of the questions you'll have.
Yeah, I just tried it..and it only works if that is exactly what I put into the txtbox, but as the data is always going to change, it doesnt work.
Why wont this work?
frmTxtLog.Text1 = frmTxtLog.Text1 & vbNewLine & data
frmTxtLog.Text1 = Mid(frmTxtLog.Text1, 7, Len(frmTxtLog.Text1) - 6)
show me a string that does not work in the method I showed you and I'll fix it.
Its the fact that I want to compile it some time and I dont want to have to go and change everything everytime i get new data. Can I just do this with yours?
Option Explicit
Private Sub Command1_Click()
Dim inData As String
Dim splitData() As String
Dim i As Integer
Text1 = ""
inData = text1 <========= right here
splitData = Split(inData, "txtlog")
For i = 0 To UBound(splitData) - 1
If Len(Trim(splitData(i))) > 0 Then _
Text1 = Text1 & Trim(splitData(i) & vbCrLf)
Next i
End Sub
Yes,
This is what I'm trying to tell you that this method works on all data as long as your marker is there to separate the data.
Show me some data where it is not working.
What am I doing wrong?Code:Public Sub txtlog1()
Dim inData As String
Dim splitData() As String
Dim i As Integer
frmTxtLog.Text1 = data
inData = frmTxtLog.Text1
splitData = Split(inData, "txtlog")
For i = 0 To UBound(splitData) - 1
If Len(Trim(splitData(i))) > 0 Then _
frmTxtLog.Text1 = frmTxtLog.Text1 & Trim(splitData(i) & vbCrLf)
Next i
End Sub
You'll have to show me how you are calling this routine.
what is data?
What input are you using and what output do you get that you don't like?
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData data
If Left$(data, 6) = "txtlog" Then txtlog1
End Sub
Thats what data is.