-
Jul 23rd, 2014, 11:19 PM
#1
Thread Starter
Lively Member
one more on my data arrival
ok i am recivived data through a proxy i made it is comeing in 2 arrivals but for some strange reason i cant get them both i tried to define buffer as data and buffer = buffer and data for second part but its losing it its a one payload just it splits just because of the time delay i guess would i use the ubound (data) but that requires an array and the only way i have ever used it was with a splitter give me your examples its right under the .getdata because the rest is in cases so i will prob get a huge buffer of data but i can say it does start with "u-" if that can be my setpoint for the buffering plz help im so stressed this is due soon and im lost ...or is there a way i can set it to just get the 2 data arrivals and make it stop with a if or case or
if mid(data,2) = "u-" then
prefix = left(data,6)
main = mid(data,7)
is what i used before i did it in a proxy
and it was fine now the prefiz works but the main it only grabs 10 of the 48 coming because the last 38 are recieved in the next dataarrival and they change so i cant set it to find it by any common bytes
-
Jul 24th, 2014, 01:36 AM
#2
Re: one more on my data arrival
define buffer as data and buffer = buffer and data
??
You must append incoming data to the buffer as it arrives. If you are using AND then that would be a problem.
If not then you should show the code you are using
-
Jul 24th, 2014, 03:30 AM
#3
Thread Starter
Lively Member
Re: one more on my data arrival
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
dim data as string,buffer as string,keyset as string
winsock1.getdata data,vbstring
buffer = buffer & data
keyset = buffer
''''' then here i would split the string up right
end sub
in the first arrival it gets 10 bytes so buffer is 38 short but immidiatly after iy arrives in next arrival the 38 remainder i assumed it would add the existing 10 bytes and the new data hence buffer & data but it forgets the first 10 and just adds the last 38 on the second arrival,,,, i rigged it to work but its really trashy code and i dont like it so how would you do this
'
-
Jul 24th, 2014, 06:40 AM
#4
Re: one more on my data arrival
You have a Variable Scoping problem:
Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data as string
Dim buffer as string
Dim keyset as string All local to the procedure so get re-initialised every time the procedure is called.
winsock1.getdata data, vbstring
buffer = buffer & data
. . .
The first time this is called, buffer is initialised (to ""), then 10 bytes added to it.
The next time it's called, buffer is re-initialised (to "" again), then 38 bytes added to it.
Solution: Move the declaration of buffer outside the procedure, as in:
Code:
Private smBuffer as String
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
. . .
Regards, Phill W.
-
Jul 24th, 2014, 09:57 AM
#5
Re: one more on my data arrival
Or
Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Static buffer as string
-
Jul 24th, 2014, 01:15 PM
#6
Re: one more on my data arrival
Your mid(data,2) = "u-" is incorrect. The 2 means the starting position and you also give no length so this will fail. What you need is mid(data, 1, 2) = "u-"
Also, if you are going to use the variables data (or buffer), prefix, main, or keyset in any other part of your program other than in the DataArrival you need to declare them in the declaration section of your code.
Also you cannot depend on the data always coming in to be in two segments. Just because it has doesn't mean it always will and if this is going to run on someone else's PC that's all the more reason you can't depend on how the data arrives. It can arrive in two segments, three, four, or whatever segments. You need to know how a particular string is going to end, like a termination code, for example, and then you buffer up the incoming data until you read that termination code.
Last edited by jmsrickland; Jul 24th, 2014 at 03:01 PM.
Reason: Removed paragraph that wasn't correct
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 24th, 2014, 01:39 PM
#7
Re: one more on my data arrival
Also, it is not a good idea to define Static buffer as string in the DataArrival because you may need to clear out any previous data in the buffer before you do something else that will call the DataArrival so this should definitely be defined in the declaration section as Phil.W posted
If you need access to the variable outside the sub then yes it needs to be defined at the form level or possibly even at a module level and made public.
If it does not need to be available elsewhere but needs to retain its value within repeated calls to the sub then it should be defined as static with in the sub
As a general rule you should not define variables at a higher level than will be needed for the task at hand so whether or not it is a good idea to use one method over the other is totally dependent on the task at hand.
-
Jul 24th, 2014, 02:13 PM
#8
Re: one more on my data arrival
I agree with DM. The buffer is specific to the DataArrival event and should be defined as Static in that routine. Irrespective of its scope the buffer will need managing.
1. You have to accumulate data into the buffer until you have at least one complete 'record'
2. When the buffer has been fully processed it must be flushed
3. After a logical record has been processed from the buffer it should be removed and the buffer checked for more data
EDIT: BTW @JM - MID$("abcde",2) is perfectly valid and will return bcde
i.e. it will return from the offset to the end of the string
Last edited by Doogle; Jul 24th, 2014 at 02:18 PM.
-
Jul 24th, 2014, 03:03 PM
#9
Re: one more on my data arrival
Thanks, DM and Doogle for correcting me. I edited my post and removed that paragraph
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 25th, 2014, 12:47 AM
#10
Thread Starter
Lively Member
atamiser phill strikland and doodle i thank you for your help all makes since
it was setting back to """" because my dumb a$$ was declaring it as string after the getdata i declared it in for declarations as private and it works great ive never seen the static buffer as string but i assume that means it continuous in that perticukar function but i got it the way i said do you think it would be more prof to use the static since i dont need the buffer data except in that datarivvale sub its not used anywhere else i parse it in the data arrival.... or should i create a function in the module to parse this but that wouldnt be prof cuz its not used anywhere else i think the static will be the prof i just private buffer as string in the form decla i got a real question that i need help with not with anything but help i wrote a proj and im no prof and in it i have a bunch of boolean true or falses in my datarrival i did it to force it to work but i think i could set cases in those and i may not need it but my ? is if i post a dataarrival code could any of you loook at it and tell me how trashy it is and how i could make it more efficient it works as it but i got 4 or 5 if blah = then else
on the arrival to my thought force my results probs to you guys !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thanks you alot
-
Jul 25th, 2014, 01:09 AM
#11
Re: one more on my data arrival
The Static declaration is specifically for a variable that is local to a function or sub but needs to retain its value so yes Static would be the correct choice in this case.
-
Jul 25th, 2014, 02:18 AM
#12
Re: one more on my data arrival
Originally Posted by Doogle
EDIT: BTW @JM - MID$("abcde",2) is perfectly valid and will return bcde
i.e. it will return from the offset to the end of the string
Thanks for the info but I already knew that so why are you telling me this?
Last edited by jmsrickland; Jul 25th, 2014 at 02:26 AM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 25th, 2014, 02:55 AM
#13
Re: one more on my data arrival
Originally Posted by jmsrickland
Thanks for the info but I already knew that so why are you telling me this?
your statement in Post#6 - states that the Mid$ will fail. I was just pointing out that the length is not mandatory.
-
Jul 25th, 2014, 12:57 PM
#14
Re: one more on my data arrival
Originally Posted by Doogle
your statement in Post#6 - states that the Mid$ will fail. I was just pointing out that the length is not mandatory.
You mis-read my post
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 25th, 2014, 01:58 PM
#15
Re: one more on my data arrival
Yes the OP was apparently looking to get the 1st 2 characters in the string but was passing 2 as a starting position and no length so it would never return what he was expecting
It would be required to pass 1 as the starting point and 2 as the length in order to grab the first 2 characters and check for a match as was stated in post #6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|